<!-- Kamailio Pull Request Template -->
<!-- IMPORTANT: - for detailed contributing guidelines, read: https://github.com/kamailio/kamailio/blob/master/.github/CONTRIBUTING.md - pull requests must be done to master branch, unless they are backports of fixes from master branch to a stable branch - backports to stable branches must be done with 'git cherry-pick -x ...' - code is contributed under BSD for core and main components (tm, sl, auth, tls) - code is contributed GPLv2 or a compatible license for the other components - GPL code is contributed with OpenSSL licensing exception -->
#### Pre-Submission Checklist <!-- Go over all points below, and after creating the PR, tick all the checkboxes that apply --> <!-- All points should be verified, otherwise, read the CONTRIBUTING guidelines from above--> <!-- If you're unsure about any of these, don't hesitate to ask on sr-dev mailing list --> - [x] Commit message has the format required by CONTRIBUTING guide - [x] Commits are split per component (core, individual modules, libs, utils, ...) - [x] Each component has a single commit (if not, squash them into one commit) - [x] No commits to README files for modules (changes must be done to docbook files in `doc/` subfolder, the README file is autogenerated)
#### Type Of Change - [ ] Small bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds new functionality) - [ ] Breaking change (fix or feature that would change existing functionality)
#### Checklist: <!-- Go over all points below, and after creating the PR, tick the checkboxes that apply --> - [ ] PR should be backported to stable branches - [x] Tested changes locally - [ ] Related to issue #XXXX (replace XXXX with an open issue number)
#### Description 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
You can view, comment on, or merge this pull request online at:
https://github.com/kamailio/kamailio/pull/2133
-- Commit Summary --
* keepalive : added new function del_destination and added .cfg functions
-- File Changes --
M src/modules/keepalive/api.h (4) M src/modules/keepalive/keepalive.h (10) M src/modules/keepalive/keepalive_api.c (117) M src/modules/keepalive/keepalive_core.c (14) M src/modules/keepalive/keepalive_mod.c (93)
-- Patch Links --
https://github.com/kamailio/kamailio/pull/2133.patch https://github.com/kamailio/kamailio/pull/2133.diff
There is two issue,
- I couldn't decide how to clean old address that passed counter, cleaning with a timer thread or when counter passed limit .
- When address is a tcp connection , callback cant catch state. how to solve this problem?
After reviews , i will add doc for functions.
@gbour - some comments from your side about this extensions from Yasin?
It seems that Guilliaume recently changed jobs, see if some others developers can comment here.
A quick look and there are some issues, I will post specific details soon.
miconda requested changes on this pull request.
- LM_INFO("adding destination: %.*s\n", uri->len, uri->s); + LM_DBG("adding destination: %.*s\n", uri->len, uri->s); + + if(ka_find_destination(uri , owner , &dest , &dest)){ + LM_INFO("uri [%.*s] already in stack --ignoring \r\n",uri->len, uri->s); + dest->counter=0;
The change of the `dest->counter` is done out of the mutex zone and this operation can be done on an invalid structure if the `dest` was removed meanwhile.
+* @abstract deletes given sip uri in allocated destination stack as named ka_alloc_destinations_list
+* +* @param msg sip message +* @param uri given uri +* @param owner given owner name, not using now +* * +* @result 1 successful , -1 fail +*/ +int ka_del_destination(str *uri, str *owner){ + + ka_dest_t *target=0,*head=0; + + if(!ka_find_destination(uri,owner,&target,&head)){ + LM_ERR("Couldnt find destination \r\n"); + return -1; + }
Similar issues, `target` and `head` are retrieved from `ka_find_destination()`, followed by code out of the mutex zone and later used directly, but at that time any of them can be already deleted. So removal has to be done in the same mutex zone as it is searched.
Actually I do not see any good use for `ka_find_destination()` returning `target` and `head`. The function can be useful to know if the address exists, but using `target` and `head` after this function expose to segfault. Either you keep the lock set in the function at the return time and unlock later, out of the function, or just make it to return true/false on finding the destination, without returning `target` and `head`.
extern struct tm_binds tmb;
int ka_ping_interval = 30; ka_destinations_list_t *ka_destinations_list = NULL; +str ka_ping_from = str_init("sip:keepalive@kamailio.org"); +int counter_del = 5;
I suggest adding `ka_` prefix to global variables that are not static and exposed in other files via `extern`.
static cmd_export_t cmds[] = { {"is_alive", (cmd_function)w_cmd_is_alive, 1, fixup_spve_null, 0, ANY_ROUTE}, // internal API + {"add_destination", (cmd_function)w_add_destination, 2, + fixup_add_destination, 0, REQUEST_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE}, + {"del_destination", (cmd_function)w_del_destination, 2, + fixup_add_destination, 0, ANY_ROUTE},
As more functions are exported from this module, I think is better to also prefix the exported name with `ka_`, like most modules use a common prefix for their functions. Probably we should also add an alias named `ka_is_alive()` for `is_alive()`.
@@ -126,6 +138,8 @@ static int mod_init(void)
*/ static void mod_destroy(void) { + lock_release(ka_destinations_list->lock); + lock_dealloc(ka_destinations_list->lock); }
This two have to be enclosed in `if(ka_destinations_list) { ... }`, the mod_destroy() is executed even when mod_init() is not finished, in that case ka_destinations_list is NULL, crashing kamailio at shutdown.
Thanks for review. I will work on these at weekend.
@ycaner06 pushed 1 commit.
54ae3c3d93cd90366be019c7096b5d2dcc78ada2 keepalive : fixed function names and re-placed un/lock functions
if it is ok , will add doc.
You can add the docs.
@ycaner06 pushed 1 commit.
9289bfc4deec22fd210d91a1174479c3ae69ed5c keepalive : added doc for exported new functions ka_add_destination and ka_del_destination [skip ci]
Merged #2133 into master.
Thanks!