Browse code

keepalive: fix initialization when using destination mod param

- Fixed the way the module is initialized, causing problems when using
destination mod parameter because when invoking this parameter some
utilities are not initialized (timers).

Nacho Garcia Segovia authored on 16/12/2020 18:21:59
Showing 1 changed files
... ...
@@ -57,6 +57,14 @@ typedef void (*ka_response_f)(
57 57
 		str *uri, struct tmcb_params *ps, void *user_attr);
58 58
 
59 59
 
60
+typedef struct _ka_initial_dest
61
+{
62
+	str uri;
63
+	str owner;
64
+	struct _ka_initial_dest *next;
65
+} ka_initial_dest_t;
66
+
67
+
60 68
 typedef struct _ka_dest
61 69
 {
62 70
 	str uri;
Browse code

keepalive: prevent race condition when deleting a destination

- Added a lock to ka_dest type, so we get it when we run callbacks that may be associated to an OPTIONS response
- Same lock is used to not remove destinations that are running callbacks
- Now find destinations consider owner and uri

Nacho Garcia Segovia authored on 14/09/2020 11:18:37
Showing 1 changed files
... ...
@@ -77,6 +77,7 @@ typedef struct _ka_dest
77 77
 	unsigned short int port;   /*!< Port of the URI */
78 78
 	unsigned short int proto;  /*!< Protocol of the URI */
79 79
 	struct timer_ln *timer;    /*!< Timer firing the OPTIONS test */
80
+	gen_lock_t lock;		   /*!< Lock of this record to prevent being removed while running */
80 81
 	struct _ka_dest *next;
81 82
 } ka_dest_t;
82 83
 
Browse code

keepalive: added uuid to ka_dest structure to avoid passing the whole struct to tm

- This avoids a race condition that may happen processing tm_request callbacl
- Allows to identify uniquely a ka_dest record

Nacho Garcia Segovia authored on 02/09/2020 13:15:41
Showing 1 changed files
... ...
@@ -31,6 +31,8 @@
31 31
 #include <time.h>
32 32
 #include "../../core/sr_module.h"
33 33
 #include "../../core/locking.h"
34
+#include "../../core/str.h"
35
+#include "../../core/utils/sruid.h"
34 36
 #include "../tm/tm_load.h"
35 37
 
36 38
 #define KA_INACTIVE_DST 1 /*!< inactive destination */
... ...
@@ -60,6 +62,7 @@ typedef struct _ka_dest
60 62
 	str uri;
61 63
 	str owner; // name of destination "owner"
62 64
 			   // (module asking to monitor this destination
65
+	str  uuid; // Universal id for this record
63 66
 	int flags;
64 67
 	int state;
65 68
 	time_t last_checked, last_up, last_down;
... ...
@@ -85,6 +88,7 @@ typedef struct _ka_destinations_list
85 88
 
86 89
 extern ka_destinations_list_t *ka_destinations_list;
87 90
 extern int ka_counter_del;
91
+extern sruid_t ka_sruid;
88 92
 
89 93
 ticks_t ka_check_timer(ticks_t ticks, struct timer_ln* tl, void* param);
90 94
 
... ...
@@ -96,6 +100,7 @@ int ka_str_copy(str *src, str *dest, char *prefix);
96 100
 int free_destination(ka_dest_t *dest) ;
97 101
 int ka_del_destination(str *uri, str *owner) ;
98 102
 int ka_find_destination(str *uri, str *owner, ka_dest_t **target ,ka_dest_t **head);
103
+int ka_find_destination_by_uuid(str uuid, ka_dest_t **target, ka_dest_t **head);
99 104
 int ka_lock_destination_list();
100 105
 int ka_unlock_destination_list();
101 106
 #endif
Browse code

keepalive: early start of OPTIONS checking

- Current code takes some time to start checking (ping_interval). So, if someone sets a really high ping_interval it takes a while to get destination status. This change fires the first OPTIONS check just 3 seconds (fixed) after the destination is added. The checks would be done with the pace defined in ping_interval.

Nacho Garcia Segovia authored on 15/05/2020 06:21:15
Showing 1 changed files
... ...
@@ -48,6 +48,8 @@ extern int ka_ping_interval;
48 48
 #define KA_PROBE_INACTIVE 2
49 49
 #define KA_PROBE_ONLYFLAGGED 3
50 50
 
51
+#define KA_FIRST_TRY_DELAY 500 /* First OPTIONS send is done 500 millis after adding the destination */
52
+
51 53
 typedef void (*ka_statechanged_f)(str *uri, int state, void *user_attr);
52 54
 typedef void (*ka_response_f)(
53 55
 		str *uri, struct tmcb_params *ps, void *user_attr);
... ...
@@ -62,6 +64,7 @@ typedef struct _ka_dest
62 64
 	int state;
63 65
 	time_t last_checked, last_up, last_down;
64 66
 	int counter;	// counts unreachable attemps
67
+	ticks_t ping_interval;  /*!< Actual interval between OPTIONS  */
65 68
 
66 69
 	void *user_attr;
67 70
 	ka_statechanged_f statechanged_clb;
... ...
@@ -70,7 +73,7 @@ typedef struct _ka_dest
70 73
 	struct ip_addr ip_address; /*!< IP-Address of the entry */
71 74
 	unsigned short int port;   /*!< Port of the URI */
72 75
 	unsigned short int proto;  /*!< Protocol of the URI */
73
-	struct timer_ln *timer;
76
+	struct timer_ln *timer;    /*!< Timer firing the OPTIONS test */
74 77
 	struct _ka_dest *next;
75 78
 } ka_dest_t;
76 79
 
Browse code

keepalive: Added callback to run on each destination response.

- This functionality it's just available when using api.h bindings. For exported functions no callback will be used, so this doesn't break cfg or rpc api.
- Modified add_destination function to provide this new callback as a parameter.

Nacho Garcia Segovia authored on 07/05/2020 21:50:10
Showing 1 changed files
... ...
@@ -31,6 +31,7 @@
31 31
 #include <time.h>
32 32
 #include "../../core/sr_module.h"
33 33
 #include "../../core/locking.h"
34
+#include "../tm/tm_load.h"
34 35
 
35 36
 #define KA_INACTIVE_DST 1 /*!< inactive destination */
36 37
 #define KA_TRYING_DST 2   /*!< temporary trying destination */
... ...
@@ -48,6 +49,8 @@ extern int ka_ping_interval;
48 49
 #define KA_PROBE_ONLYFLAGGED 3
49 50
 
50 51
 typedef void (*ka_statechanged_f)(str *uri, int state, void *user_attr);
52
+typedef void (*ka_response_f)(
53
+		str *uri, struct tmcb_params *ps, void *user_attr);
51 54
 
52 55
 
53 56
 typedef struct _ka_dest
... ...
@@ -62,6 +65,7 @@ typedef struct _ka_dest
62 65
 
63 66
 	void *user_attr;
64 67
 	ka_statechanged_f statechanged_clb;
68
+	ka_response_f response_clb;
65 69
 	struct socket_info *sock;
66 70
 	struct ip_addr ip_address; /*!< IP-Address of the entry */
67 71
 	unsigned short int port;   /*!< Port of the URI */
... ...
@@ -82,7 +86,8 @@ extern int ka_counter_del;
82 86
 ticks_t ka_check_timer(ticks_t ticks, struct timer_ln* tl, void* param);
83 87
 
84 88
 int ka_add_dest(str *uri, str *owner, int flags, int ping_interval,
85
-        ka_statechanged_f callback, void *user_attr);
89
+        ka_statechanged_f statechanged_clb, ka_response_f response_clb,
90
+        void *user_attr);
86 91
 int ka_destination_state(str *uri);
87 92
 int ka_str_copy(str *src, str *dest, char *prefix);
88 93
 int free_destination(ka_dest_t *dest) ;
Browse code

keepalive: custom pinging interval per destination

- This functionality it's just available when using api.h bindings. For exported functions current value ka_ping_interval is used.
- Modified add_destination function to provide this new parameter.
- Now we have one timer per destination, instead of multiple, so we don't need to iterate over all destinations. Timers are cleaned when destinations are removed.

Nacho Garcia Segovia authored on 06/05/2020 21:10:40
Showing 1 changed files
... ...
@@ -38,6 +38,8 @@
38 38
 #define KA_PROBING_DST 8  /*!< checking destination */
39 39
 #define KA_STATES_ALL 15  /*!< all bits for the states of destination */
40 40
 
41
+extern int ka_ping_interval;
42
+
41 43
 #define ds_skip_dst(flags) ((flags) & (KA_INACTIVE_DST | KA_DISABLED_DST))
42 44
 
43 45
 #define KA_PROBE_NONE 0
... ...
@@ -64,6 +66,7 @@ typedef struct _ka_dest
64 66
 	struct ip_addr ip_address; /*!< IP-Address of the entry */
65 67
 	unsigned short int port;   /*!< Port of the URI */
66 68
 	unsigned short int proto;  /*!< Protocol of the URI */
69
+	struct timer_ln *timer;
67 70
 	struct _ka_dest *next;
68 71
 } ka_dest_t;
69 72
 
... ...
@@ -76,8 +79,10 @@ typedef struct _ka_destinations_list
76 79
 extern ka_destinations_list_t *ka_destinations_list;
77 80
 extern int ka_counter_del;
78 81
 
79
-int ka_add_dest(str *uri, str *owner, int flags, ka_statechanged_f callback,
80
-		void *user_attr);
82
+ticks_t ka_check_timer(ticks_t ticks, struct timer_ln* tl, void* param);
83
+
84
+int ka_add_dest(str *uri, str *owner, int flags, int ping_interval,
85
+        ka_statechanged_f callback, void *user_attr);
81 86
 int ka_destination_state(str *uri);
82 87
 int ka_str_copy(str *src, str *dest, char *prefix);
83 88
 int free_destination(ka_dest_t *dest) ;
Browse code

keepalive : added new function del_destination and added cfg functions (#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

Yasin CANER authored on 12/12/2019 11:06:24 • Daniel-Constantin Mierla committed on 12/12/2019 11:06:24
Showing 1 changed files
... ...
@@ -30,7 +30,7 @@
30 30
 
31 31
 #include <time.h>
32 32
 #include "../../core/sr_module.h"
33
-
33
+#include "../../core/locking.h"
34 34
 
35 35
 #define KA_INACTIVE_DST 1 /*!< inactive destination */
36 36
 #define KA_TRYING_DST 2   /*!< temporary trying destination */
... ...
@@ -47,6 +47,7 @@
47 47
 
48 48
 typedef void (*ka_statechanged_f)(str *uri, int state, void *user_attr);
49 49
 
50
+
50 51
 typedef struct _ka_dest
51 52
 {
52 53
 	str uri;
... ...
@@ -55,10 +56,10 @@ typedef struct _ka_dest
55 56
 	int flags;
56 57
 	int state;
57 58
 	time_t last_checked, last_up, last_down;
59
+	int counter;	// counts unreachable attemps
58 60
 
59 61
 	void *user_attr;
60 62
 	ka_statechanged_f statechanged_clb;
61
-
62 63
 	struct socket_info *sock;
63 64
 	struct ip_addr ip_address; /*!< IP-Address of the entry */
64 65
 	unsigned short int port;   /*!< Port of the URI */
... ...
@@ -68,14 +69,20 @@ typedef struct _ka_dest
68 69
 
69 70
 typedef struct _ka_destinations_list
70 71
 {
72
+	gen_lock_t *lock;
71 73
 	ka_dest_t *first;
72 74
 } ka_destinations_list_t;
73 75
 
74 76
 extern ka_destinations_list_t *ka_destinations_list;
77
+extern int ka_counter_del;
75 78
 
76 79
 int ka_add_dest(str *uri, str *owner, int flags, ka_statechanged_f callback,
77 80
 		void *user_attr);
78 81
 int ka_destination_state(str *uri);
79 82
 int ka_str_copy(str *src, str *dest, char *prefix);
80
-
83
+int free_destination(ka_dest_t *dest) ;
84
+int ka_del_destination(str *uri, str *owner) ;
85
+int ka_find_destination(str *uri, str *owner, ka_dest_t **target ,ka_dest_t **head);
86
+int ka_lock_destination_list();
87
+int ka_unlock_destination_list();
81 88
 #endif
Browse code

keepalive: allow variables in cfg function parameters

- use str* instead of str for api functions

Daniel-Constantin Mierla authored on 29/05/2017 05:18:14
Showing 1 changed files
... ...
@@ -45,7 +45,7 @@
45 45
 #define KA_PROBE_INACTIVE 2
46 46
 #define KA_PROBE_ONLYFLAGGED 3
47 47
 
48
-typedef void (*ka_statechanged_f)(str uri, int state, void *user_attr);
48
+typedef void (*ka_statechanged_f)(str *uri, int state, void *user_attr);
49 49
 
50 50
 typedef struct _ka_dest
51 51
 {
... ...
@@ -73,9 +73,9 @@ typedef struct _ka_destinations_list
73 73
 
74 74
 extern ka_destinations_list_t *ka_destinations_list;
75 75
 
76
-int ka_add_dest(str uri, str owner, int flags, ka_statechanged_f callback,
76
+int ka_add_dest(str *uri, str *owner, int flags, ka_statechanged_f callback,
77 77
 		void *user_attr);
78
-int ka_destination_state(str uri);
79
-int ka_str_copy(str src, str *dest, char *prefix);
78
+int ka_destination_state(str *uri);
79
+int ka_str_copy(str *src, str *dest, char *prefix);
80 80
 
81 81
 #endif
Browse code

keepalive: format to match default conding style and 80 chars lines

Daniel-Constantin Mierla authored on 05/04/2017 06:52:01
Showing 1 changed files
... ...
@@ -32,39 +32,37 @@
32 32
 #include "../../core/sr_module.h"
33 33
 
34 34
 
35
-#define KA_INACTIVE_DST		1  /*!< inactive destination */
36
-#define KA_TRYING_DST		2  /*!< temporary trying destination */
37
-#define KA_DISABLED_DST		4  /*!< admin disabled destination */
38
-#define KA_PROBING_DST		8  /*!< checking destination */
39
-#define KA_STATES_ALL		15  /*!< all bits for the states of destination */
35
+#define KA_INACTIVE_DST 1 /*!< inactive destination */
36
+#define KA_TRYING_DST 2   /*!< temporary trying destination */
37
+#define KA_DISABLED_DST 4 /*!< admin disabled destination */
38
+#define KA_PROBING_DST 8  /*!< checking destination */
39
+#define KA_STATES_ALL 15  /*!< all bits for the states of destination */
40 40
 
41
-#define ds_skip_dst(flags)	((flags) & (KA_INACTIVE_DST|KA_DISABLED_DST))
41
+#define ds_skip_dst(flags) ((flags) & (KA_INACTIVE_DST | KA_DISABLED_DST))
42 42
 
43
-#define KA_PROBE_NONE			0
44
-#define KA_PROBE_ALL			1
45
-#define KA_PROBE_INACTIVE		2
46
-#define KA_PROBE_ONLYFLAGGED	3
43
+#define KA_PROBE_NONE 0
44
+#define KA_PROBE_ALL 1
45
+#define KA_PROBE_INACTIVE 2
46
+#define KA_PROBE_ONLYFLAGGED 3
47 47
 
48 48
 typedef void (*ka_statechanged_f)(str uri, int state, void *user_attr);
49 49
 
50 50
 typedef struct _ka_dest
51 51
 {
52 52
 	str uri;
53
-	str owner;                  // name of destination "owner"
54
-                                // (module asking to monitor this destination
53
+	str owner; // name of destination "owner"
54
+			   // (module asking to monitor this destination
55 55
 	int flags;
56 56
 	int state;
57
-	time_t last_checked,
58
-		   last_up,
59
-		   last_down;
57
+	time_t last_checked, last_up, last_down;
60 58
 
61 59
 	void *user_attr;
62 60
 	ka_statechanged_f statechanged_clb;
63 61
 
64
-	struct socket_info * sock;
65
-	struct ip_addr ip_address; 	/*!< IP-Address of the entry */
66
-	unsigned short int port; 	/*!< Port of the URI */
67
-	unsigned short int proto; 	/*!< Protocol of the URI */
62
+	struct socket_info *sock;
63
+	struct ip_addr ip_address; /*!< IP-Address of the entry */
64
+	unsigned short int port;   /*!< Port of the URI */
65
+	unsigned short int proto;  /*!< Protocol of the URI */
68 66
 	struct _ka_dest *next;
69 67
 } ka_dest_t;
70 68
 
... ...
@@ -75,9 +73,9 @@ typedef struct _ka_destinations_list
75 73
 
76 74
 extern ka_destinations_list_t *ka_destinations_list;
77 75
 
78
-int ka_add_dest(str uri, str owner, int flags, ka_statechanged_f callback, void *user_attr);
76
+int ka_add_dest(str uri, str owner, int flags, ka_statechanged_f callback,
77
+		void *user_attr);
79 78
 int ka_destination_state(str uri);
80 79
 int ka_str_copy(str src, str *dest, char *prefix);
81 80
 
82 81
 #endif
83
-
Browse code

keepalive: declare variables at the beginning of functions

- fix for C standard older than C99

Daniel-Constantin Mierla authored on 05/04/2017 06:45:33
Showing 1 changed files
... ...
@@ -1,6 +1,6 @@
1 1
 /**
2 2
  * keepalive module - remote destinations probing
3
- * 
3
+ *
4 4
  * Copyright (C) 2017 Guillaume Bour <guillaume@bour.cc>
5 5
  *
6 6
  * This file is part of Kamailio, a free SIP server.
... ...
@@ -15,8 +15,8 @@
15 15
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 16
  * GNU General Public License for more details.
17 17
  *
18
- * You should have received a copy of the GNU General Public License 
19
- * along with this program; if not, write to the Free Software 
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program; if not, write to the Free Software
20 20
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21 21
  */
22 22
 
... ...
@@ -57,7 +57,6 @@ typedef struct _ka_dest
57 57
 	time_t last_checked,
58 58
 		   last_up,
59 59
 		   last_down;
60
-	//ds_attrs_t attrs;
61 60
 
62 61
 	void *user_attr;
63 62
 	ka_statechanged_f statechanged_clb;
... ...
@@ -66,7 +65,6 @@ typedef struct _ka_dest
66 65
 	struct ip_addr ip_address; 	/*!< IP-Address of the entry */
67 66
 	unsigned short int port; 	/*!< Port of the URI */
68 67
 	unsigned short int proto; 	/*!< Protocol of the URI */
69
-	//int message_count;
70 68
 	struct _ka_dest *next;
71 69
 } ka_dest_t;
72 70
 
Browse code

keepalive: new module to monitor remote destinations

Guillaume Bour authored on 04/04/2017 14:00:15 • Daniel-Constantin Mierla committed on 04/04/2017 14:00:15
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,85 @@
1
+/**
2
+ * keepalive module - remote destinations probing
3
+ * 
4
+ * Copyright (C) 2017 Guillaume Bour <guillaume@bour.cc>
5
+ *
6
+ * This file is part of Kamailio, a free SIP server.
7
+ *
8
+ * Kamailio is free software; you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation; either version 2 of the License, or
11
+ * (at your option) any later version
12
+ *
13
+ * Kamailio is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License 
19
+ * along with this program; if not, write to the Free Software 
20
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21
+ */
22
+
23
+/*! \file
24
+ * \ingroup keepalive
25
+ * \brief Keepalive :: Keepalive
26
+ */
27
+
28
+#ifndef _KEEPALIVE_H_
29
+#define _KEEPALIVE_H_
30
+
31
+#include <time.h>
32
+#include "../../core/sr_module.h"
33
+
34
+
35
+#define KA_INACTIVE_DST		1  /*!< inactive destination */
36
+#define KA_TRYING_DST		2  /*!< temporary trying destination */
37
+#define KA_DISABLED_DST		4  /*!< admin disabled destination */
38
+#define KA_PROBING_DST		8  /*!< checking destination */
39
+#define KA_STATES_ALL		15  /*!< all bits for the states of destination */
40
+
41
+#define ds_skip_dst(flags)	((flags) & (KA_INACTIVE_DST|KA_DISABLED_DST))
42
+
43
+#define KA_PROBE_NONE			0
44
+#define KA_PROBE_ALL			1
45
+#define KA_PROBE_INACTIVE		2
46
+#define KA_PROBE_ONLYFLAGGED	3
47
+
48
+typedef void (*ka_statechanged_f)(str uri, int state, void *user_attr);
49
+
50
+typedef struct _ka_dest
51
+{
52
+	str uri;
53
+	str owner;                  // name of destination "owner"
54
+                                // (module asking to monitor this destination
55
+	int flags;
56
+	int state;
57
+	time_t last_checked,
58
+		   last_up,
59
+		   last_down;
60
+	//ds_attrs_t attrs;
61
+
62
+	void *user_attr;
63
+	ka_statechanged_f statechanged_clb;
64
+
65
+	struct socket_info * sock;
66
+	struct ip_addr ip_address; 	/*!< IP-Address of the entry */
67
+	unsigned short int port; 	/*!< Port of the URI */
68
+	unsigned short int proto; 	/*!< Protocol of the URI */
69
+	//int message_count;
70
+	struct _ka_dest *next;
71
+} ka_dest_t;
72
+
73
+typedef struct _ka_destinations_list
74
+{
75
+	ka_dest_t *first;
76
+} ka_destinations_list_t;
77
+
78
+extern ka_destinations_list_t *ka_destinations_list;
79
+
80
+int ka_add_dest(str uri, str owner, int flags, ka_statechanged_f callback, void *user_attr);
81
+int ka_destination_state(str uri);
82
+int ka_str_copy(str src, str *dest, char *prefix);
83
+
84
+#endif
85
+