Skip to content

Commit

Permalink
keepalive : added new function del_destination and added cfg functions (
Browse files Browse the repository at this point in the history
#2133)

* keepalive : added new function del_destination and added .cfg functions

added new function del_destination that deletes sip address from list
added add_destination module functions for kamailio.cfg
added counter parameter for attempt count. after count pass, module dont try until it adds again.
added kemi interfaces both of them
added lock to stack
added find_destination function

* keepalive : fixed function names and re-placed un/lock functions

fixed function names and re-placed un/lock functions

* keepalive : added doc for exported new functions ka_add_destination and ka_del_destination [skip ci]

added documents for exported new function  ka_add_destination and ka_del_destination
renamed in documents from is_alive to ka_is_alive
added missing rpc command in documents
  • Loading branch information
ycaner06 authored and miconda committed Dec 12, 2019
1 parent ae08b59 commit e8bd86d
Show file tree
Hide file tree
Showing 7 changed files with 386 additions and 27 deletions.
8 changes: 8 additions & 0 deletions src/modules/keepalive/api.h
Expand Up @@ -40,11 +40,19 @@ typedef int ka_state;
typedef int (*ka_add_dest_f)(str *uri, str *owner, int flags,
ka_statechanged_f callback, void *user_attr);
typedef ka_state (*ka_dest_state_f)(str *uri);
typedef int (*ka_del_destination_f)(str *uri, str *owner);
typedef int (*ka_find_destination_f)(str *uri, str *owner,ka_dest_t **target,ka_dest_t **head);
typedef int (*ka_lock_destination_list_f)();
typedef int (*ka_unlock_destination_list_f)();

typedef struct keepalive_api
{
ka_add_dest_f add_destination;
ka_dest_state_f destination_state;
ka_del_destination_f del_destination;
ka_find_destination_f find_destination;
ka_lock_destination_list_f lock_destination_list;
ka_unlock_destination_list_f unlock_destination_list;
} keepalive_api_t;

typedef int (*bind_keepalive_f)(keepalive_api_t *api);
Expand Down
14 changes: 13 additions & 1 deletion src/modules/keepalive/doc/keepalive.xml
Expand Up @@ -18,13 +18,25 @@
<surname>Bour</surname>
<email>guillaume@bour.cc</email>
</author>

<author>
<firstname>Yasin</firstname>
<surname>CANER</surname>
<email>caner_yaso@hotmail.com</email>
</author>

<editor>
<firstname>Guillaume</firstname>
<surname>Bour</surname>
<email>guillaume@bour.cc</email>
</editor>

<editor>
<firstname>Yasin</firstname>
<surname>CANER</surname>
<email>caner_yaso@hotmail.com</email>
</editor>
</authorgroup>

<copyright>
<year>2017</year>
<holder>Guillaume Bour</holder>
Expand Down
125 changes: 121 additions & 4 deletions src/modules/keepalive/doc/keepalive_admin.xml
Expand Up @@ -89,6 +89,44 @@ modparam("keepalive", "ping_interval", 10)
...
modparam("keepalive", "destination", "192.168.10.20")
modparam("keepalive", "destination", "sip.provider.com")
...
</programlisting>
</example>
</section>
<section>
<title><varname>delete_counter</varname>(int)</title>
<para>
Unsuccesful attemps increase delete_counter . After passing it , keepalive module doesn't try to send options requests.
</para>
<para>
<emphasis>
Default value is 5 .
</emphasis>
</para>
<example>
<title>Set <varname>delete_counter</varname> parameter</title>
<programlisting format="linespecific">
...
modparam("keepalive", "delete_counter", "5")
...
</programlisting>
</example>
</section>
<section>
<title><varname>ping_from</varname>(string)</title>
<para>
Sets from header's uri.
</para>
<para>
<emphasis>
Default value is "sip:keepalive@kamailio.org" .
</emphasis>
</para>
<example>
<title>Set <varname>ping_from</varname> parameter</title>
<programlisting format="linespecific">
...
modparam("keepalive", "ping_from", "sip:keepalive@kamailio.org")
...
</programlisting>
</example>
Expand All @@ -97,9 +135,9 @@ modparam("keepalive", "destination", "sip.provider.com")

<section>
<title>Functions</title>
<section id="keepalive.is_alive">
<section id="keepalive.ka_is_alive">
<title>
<function moreinfo="none">is_alive(destination)</function>
<function moreinfo="none">ka_is_alive(destination)</function>
</title>
<para>
Get destination status.
Expand All @@ -119,16 +157,95 @@ modparam("keepalive", "destination", "sip.provider.com")
This function can be used from ANY_ROUTE.
</para>
<example>
<title><function>is_alive()</function> usage</title>
<title><function>ka_is_alive()</function> usage</title>
<programlisting format="linespecific">
...
if(is_alive("192.168.10.20") == 1) {
if(ka_is_alive("192.168.10.20") == 1) {
// do stuff
};
...
</programlisting>
</example>
</section>
<section id="keepalive.ka_add_destination">
<title>
<function moreinfo="none">ka_add_destination(sip_uri)</function>
</title>
<para>
Adds destination sip/sips uri in memory list to keep alive .
</para>
<para>
Returned value:
<itemizedlist>
<listitem>1 - successful </listitem>
<listitem>-1 - on error</listitem>
</itemizedlist>
</para>
<para>
This function can be used from REQUEST_ROUTE,BRANCH_ROUTE,ONREPLY_ROUTE.
</para>
<example>
<title><function>ka_add_destination(sip_uri)</function> usage</title>
<programlisting format="linespecific">
...
$avp(duri1)="sip:192.168.1.10:5060;transport=tcp";
$avp(duri2)="sip:192.168.1.11:5061";
$avp(duri3)="sip:192.168.1.12"
ka_add_destination("$avp(duri3)");
ka_add_destination("sip:192.168.1.10:5060;transport=tcp");
...
</programlisting>
</example>
</section>
<section id="keepalive.ka_del_destination">
<title>
<function moreinfo="none">ka_del_destination(sip_uri)</function>
</title>
<para>
Deletes destination sip/sips uri in memory list .
</para>
<para>
Returned value:
<itemizedlist>
<listitem> 1 - successful </listitem>
<listitem>-1 - on error</listitem>
</itemizedlist>
</para>
<para>
This function can be used from ANY_ROUTE.
</para>
<example>
<title><function>ka_del_destination(sip_uri)</function> usage</title>
<programlisting format="linespecific">
...
$avp(duri1)="sip:192.168.1.10:5060;transport=tcp";
$avp(duri2)="sip:192.168.1.11:5061";
$avp(duri3)="sip:192.168.1.12"
ka_del_destination("$avp(duri3)");
ka_del_destination("sip:192.168.1.10:5060;transport=tcp");
...
</programlisting>
</example>
</section>
</section>
<section>
<title>RPC Commands</title>
<section id="keepalive.list">
<title><function>keepalive.list</function></title>
<para>
Lists destinations in memory.
</para>
<para>
Name: <emphasis>keepalive.list</emphasis>
</para>
<para>Parameters: <emphasis>none</emphasis></para>
<example>
<title><function>keepalive.list</function> RPC example</title>
<programlisting format="linespecific">
keepalive.list
</programlisting>
</example>
</section>
</section>
</section>
</chapter>
Expand Down
13 changes: 10 additions & 3 deletions src/modules/keepalive/keepalive.h
Expand Up @@ -30,7 +30,7 @@

#include <time.h>
#include "../../core/sr_module.h"

#include "../../core/locking.h"

#define KA_INACTIVE_DST 1 /*!< inactive destination */
#define KA_TRYING_DST 2 /*!< temporary trying destination */
Expand All @@ -47,6 +47,7 @@

typedef void (*ka_statechanged_f)(str *uri, int state, void *user_attr);


typedef struct _ka_dest
{
str uri;
Expand All @@ -55,10 +56,10 @@ typedef struct _ka_dest
int flags;
int state;
time_t last_checked, last_up, last_down;
int counter; // counts unreachable attemps

void *user_attr;
ka_statechanged_f statechanged_clb;

struct socket_info *sock;
struct ip_addr ip_address; /*!< IP-Address of the entry */
unsigned short int port; /*!< Port of the URI */
Expand All @@ -68,14 +69,20 @@ typedef struct _ka_dest

typedef struct _ka_destinations_list
{
gen_lock_t *lock;
ka_dest_t *first;
} ka_destinations_list_t;

extern ka_destinations_list_t *ka_destinations_list;
extern int ka_counter_del;

int ka_add_dest(str *uri, str *owner, int flags, ka_statechanged_f callback,
void *user_attr);
int ka_destination_state(str *uri);
int ka_str_copy(str *src, str *dest, char *prefix);

int free_destination(ka_dest_t *dest) ;
int ka_del_destination(str *uri, str *owner) ;
int ka_find_destination(str *uri, str *owner, ka_dest_t **target ,ka_dest_t **head);
int ka_lock_destination_list();
int ka_unlock_destination_list();
#endif

0 comments on commit e8bd86d

Please sign in to comment.