Module: kamailio
Branch: master
Commit: 8797e7454f5948c0c8166bf2b938a489b3092f2d
URL:
https://github.com/kamailio/kamailio/commit/8797e7454f5948c0c8166bf2b938a48…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2023-10-26T13:34:51+02:00
usrloc: new parameter to specify reply codes for keepalive handling
- comma separated list of reply codes or reply class to be considered
valid for keepalive handling
---
Modified: src/modules/usrloc/ul_keepalive.c
Modified: src/modules/usrloc/ul_keepalive.h
Modified: src/modules/usrloc/usrloc_mod.c
---
Diff:
https://github.com/kamailio/kamailio/commit/8797e7454f5948c0c8166bf2b938a48…
Patch:
https://github.com/kamailio/kamailio/commit/8797e7454f5948c0c8166bf2b938a48…
---
diff --git a/src/modules/usrloc/ul_keepalive.c b/src/modules/usrloc/ul_keepalive.c
index 9897233ea53..02c21c0837e 100644
--- a/src/modules/usrloc/ul_keepalive.c
+++ b/src/modules/usrloc/ul_keepalive.c
@@ -315,6 +315,47 @@ unsigned long ul_ka_fromhex(str *shex, int *err)
return v;
}
+/**
+ *
+ */
+#define UL_KA_REPLY_CODES_SIZE 32
+static int _ul_ka_reply_codes[UL_KA_REPLY_CODES_SIZE] = {0};
+
+/**
+ *
+ */
+int ul_ka_parse_reply_codes(char *vcodes)
+{
+ int nb = 0;
+ char *p;
+ char *e;
+
+ _ul_ka_reply_codes[0] = 0;
+ if(vcodes == NULL || strlen(vcodes) == 0) {
+ LM_ERR("invalid parameter\n");
+ return -1;
+ }
+ p = vcodes;
+ while(nb < UL_KA_REPLY_CODES_SIZE && *p) {
+ _ul_ka_reply_codes[nb] = strtol(p, &e, 10);
+ if(_ul_ka_reply_codes[nb] > 0) {
+ nb++;
+ } else {
+ _ul_ka_reply_codes[nb] = 0;
+ }
+ while(*e == ',' || *e == ' ') {
+ e++;
+ }
+ p = e;
+ }
+ if(nb == UL_KA_REPLY_CODES_SIZE) {
+ LM_ERR("exceeded maximum number of reply code rules\n");
+ return -1;
+ }
+ _ul_ka_reply_codes[nb] = 0;
+ return 0;
+}
+
/**
*
*/
@@ -329,6 +370,7 @@ int ul_ka_reply_received(sip_msg_t *msg)
struct timeval tvm;
struct timeval tvn;
unsigned int tvdiff;
+ int i;
if(msg->cseq == NULL) {
if((parse_headers(msg, HDR_CSEQ_F, 0) == -1) || (msg->cseq == NULL)) {
@@ -345,6 +387,19 @@ int ul_ka_reply_received(sip_msg_t *msg)
return 1;
}
+ for(i = 0; _ul_ka_reply_codes[i] != 0; i++) {
+ if(_ul_ka_reply_codes[i] == msg->first_line.u.reply.statuscode
+ || _ul_ka_reply_codes[i]
+ == (msg->first_line.u.reply.statuscode / 100)) {
+ break;
+ }
+ }
+
+ if(i > 0 && _ul_ka_reply_codes[i] == 0) {
+ /* no match of status code */
+ return 1;
+ }
+
/* there must be no second via */
if(!(parse_headers(msg, HDR_VIA2_F, 0) == -1 || (msg->via2 == 0)
|| (msg->via2->error != PARSE_OK))) {
diff --git a/src/modules/usrloc/ul_keepalive.h b/src/modules/usrloc/ul_keepalive.h
index b807d392c57..8e5e684b37a 100644
--- a/src/modules/usrloc/ul_keepalive.h
+++ b/src/modules/usrloc/ul_keepalive.h
@@ -35,5 +35,6 @@
int ul_ka_urecord(urecord_t *ur);
int ul_ka_reply_received(sip_msg_t *msg);
+int ul_ka_parse_reply_codes(char *vcodes);
-#endif
\ No newline at end of file
+#endif
diff --git a/src/modules/usrloc/usrloc_mod.c b/src/modules/usrloc/usrloc_mod.c
index de75545bc78..37f4a903b86 100644
--- a/src/modules/usrloc/usrloc_mod.c
+++ b/src/modules/usrloc/usrloc_mod.c
@@ -220,6 +220,8 @@ int ul_hash_size = 10;
int ul_db_insert_null = 0;
int ul_db_timer_clean = 0;
+char *ul_ka_reply_codes_str = "0";
+
/* flags */
unsigned int ul_nat_bflag = (unsigned int)-1;
unsigned int ul_init_flag = 0;
@@ -301,6 +303,7 @@ static param_export_t params[] = {
{"ka_timeout", PARAM_INT, &ul_keepalive_timeout},
{"ka_loglevel", PARAM_INT, &ul_ka_loglevel},
{"ka_logmsg", PARAM_STR, &ul_ka_logmsg},
+ {"ka_reply_codes", PARAM_STRING, &ul_ka_reply_codes_str},
{"load_rank", PARAM_INT, &ul_load_rank},
{"db_clean_tcp", PARAM_INT, &ul_db_clean_tcp},
{0, 0, 0}
@@ -335,6 +338,9 @@ static int mod_init(void)
int i;
udomain_t *d;
+ if(ul_ka_parse_reply_codes(ul_ka_reply_codes_str)) {
+ return -1;
+ }
if(ul_rm_expired_delay != 0) {
if(ul_db_mode != DB_ONLY) {
LM_ERR("rm expired delay feature is available for db only mode\n");