### Description
Monitoring extensions by using KA function from the usrloc module it's not working for ws contacts
#### Log Messages
```
Oct 8 16:51:20 devsrv devsrv[31562]: ERROR: usrloc [ul_keepalive.c:277]: ul_ka_send(): unknown proto [5] for sending keepalive
Oct 8 16:51:50 devsrv devsrv[31562]: DEBUG: usrloc [ul_keepalive.c:112]: ul_ka_urecord(): keepalive for aor: 101
Oct 8 16:51:50 devsrv devsrv[31562]: DEBUG: usrloc [ul_keepalive.c:236]: ul_ka_urecord(): keepalive request (len: 323) [[#012OPTIONS sip:gehtfehm@eg4avcve63ua.invalid;transport=ws SIP/2.0#015#012Via: SIP/2.0/WS 192.168.0.11:443;branch=z9hG4bKx.4.1.0#015#012From: <sip:options@webrtc-gw.company.net>;tag=uloc-c-5f7f3503-7b52-1-9abde102-5f7f3596-44823-4.1#015#012To: <sip:101@webrtc-gw.company.net>#015#012Call-ID: ksrulka-4.1#015#012CSeq: 80 OPTIONS#015#012Content-Length: 0#015#012#015#012]]
Oct 8 16:51:50 devsrv devsrv[31562]: ERROR: usrloc [ul_keepalive.c:277]: ul_ka_send(): unknown proto [5] for sending keepalive
```
### Additional Information
* **Kamailio Version** - output of `kamailio -v`
```
version: kamailio 5.4.1 (x86_64/linux) a6cb74
```
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/2502
Module: kamailio
Branch: master
Commit: 5e107824d684cdf30514b033e7f600862123ece5
URL: https://github.com/kamailio/kamailio/commit/5e107824d684cdf30514b033e7f6008…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2020-10-09T07:52:29+02:00
core: tcp - helper function to send data over ws/wss connection
---
Modified: src/core/tcp_main.c
Modified: src/core/tcp_server.h
---
Diff: https://github.com/kamailio/kamailio/commit/5e107824d684cdf30514b033e7f6008…
Patch: https://github.com/kamailio/kamailio/commit/5e107824d684cdf30514b033e7f6008…
---
diff --git a/src/core/tcp_main.c b/src/core/tcp_main.c
index f19f75a588..84fec376a3 100644
--- a/src/core/tcp_main.c
+++ b/src/core/tcp_main.c
@@ -95,6 +95,7 @@
#include "tcp_info.h"
#include "tcp_options.h"
#include "ut.h"
+#include "events.h"
#include "cfg/cfg_struct.h"
#include <fcntl.h> /* must be included after io_wait.h if SIGIO_RT is used */
@@ -5135,4 +5136,88 @@ void tcp_get_info(struct tcp_gen_info *ti)
#endif /* TCP_ASYNC */
}
+
+/* finds an ws/wss tcpconn & sends on it
+ * uses the dst members to, proto (ws/wss) and id and tries to send
+ * returns: number of bytes written (>=0) on success
+ * <0 on error */
+int wss_send(dest_info_t* dst, const char* buf, unsigned len)
+{
+ int port;
+ struct ip_addr ip;
+ union sockaddr_union* from = NULL;
+ union sockaddr_union local_addr;
+ struct tcp_connection *con = NULL;
+ struct ws_event_info wsev;
+ sr_event_param_t evp = {0};
+ int ret;
+
+ if (unlikely((dst->proto == PROTO_WS
+#ifdef USE_TLS
+ || dst->proto == PROTO_WSS
#endif
+ ) && sr_event_enabled(SREV_TCP_WS_FRAME_OUT))) {
+ if (unlikely(dst->send_flags.f & SND_F_FORCE_SOCKET
+ && dst->send_sock)) {
+
+ local_addr = dst->send_sock->su;
+#ifdef SO_REUSEPORT
+ if (cfg_get(tcp, tcp_cfg, reuse_port)) {
+ LM_DBG("sending to: %s, force_socket=%d, send_sock=%p\n",
+ su2a(&dst->to,sizeof(struct sockaddr_in)),
+ (dst->send_flags.f & SND_F_FORCE_SOCKET),
+ dst->send_sock);
+
+ su_setport(&local_addr, dst->send_sock->port_no);
+ }
+ else
+ su_setport(&local_addr, 0); /* any local port will do */
+#else
+ su_setport(&local_addr, 0); /* any local port will do */
+#endif
+ from = &local_addr;
+ }
+
+ port = su_getport(&dst->to);
+ if (likely(port)) {
+ su2ip_addr(&ip, &dst->to);
+ if(tcp_connection_match==TCPCONN_MATCH_STRICT) {
+ con = tcpconn_lookup(dst->id, &ip, port, from,
+ (dst->send_sock)?dst->send_sock->port_no:0, 0);
+ } else {
+ con = tcpconn_get(dst->id, &ip, port, from, 0);
+ }
+ }
+ else if (likely(dst->id))
+ con = tcpconn_get(dst->id, 0, 0, 0, 0);
+ else {
+ LM_CRIT("null_id & to\n");
+ goto error;
+ }
+
+ if (con == NULL) {
+ LM_WARN("TCP/TLS connection for WebSocket could not be found\n");
+ goto error;
+ }
+
+ memset(&wsev, 0, sizeof(ws_event_info_t));
+ wsev.type = SREV_TCP_WS_FRAME_OUT;
+ wsev.buf = (char*)buf;
+ wsev.len = len;
+ wsev.id = con->id;
+ evp.data = (void *)&wsev;
+ ret = sr_event_exec(SREV_TCP_WS_FRAME_OUT, &evp);
+ tcpconn_put(con);
+ goto done;
+ } else {
+ LM_CRIT("used with invalid proto %d\n", dst->proto);
+ goto error;
+ }
+
+done:
+ return ret;
+error:
+ return -1;
+}
+
+#endif /* USE_TCP */
diff --git a/src/core/tcp_server.h b/src/core/tcp_server.h
index 0566c500dc..dac25bb152 100644
--- a/src/core/tcp_server.h
+++ b/src/core/tcp_server.h
@@ -13,8 +13,8 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -33,7 +33,7 @@ int tcp_send(struct dest_info* dst, union sockaddr_union* from,
int tcpconn_add_alias(int id, int port, int proto);
-
+int wss_send(dest_info_t* dst, const char* buf, unsigned len);
#endif
break large function
<!-- 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] Each component has a single commit (if not, squash them into one commit)
#### Type Of Change
- [x] refactoring (non-breaking change which adds new functionality)
#### Description
This large function `ds_manage_routes` is quite large and the intent of every code block is becoming hard to read and assess.
In order to avoid mixing refactoring with behavioral modifications I thought it was best to make a separate MR.
You can view, comment on, or merge this pull request online at:
https://github.com/kamailio/kamailio/pull/2499
-- Commit Summary --
* dispatcher: ds_manage_routes refactoring
-- File Changes --
M src/modules/dispatcher/dispatch.c (111)
-- Patch Links --
https://github.com/kamailio/kamailio/pull/2499.patchhttps://github.com/kamailio/kamailio/pull/2499.diff
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/pull/2499
Module: kamailio
Branch: master
Commit: 3f9210fc23840560c8fe33ef26b537aa32cbe6df
URL: https://github.com/kamailio/kamailio/commit/3f9210fc23840560c8fe33ef26b537a…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2020-10-08T07:48:28+02:00
CONTRIBUTING.md: more content related to commit message format
---
Modified: .github/CONTRIBUTING.md
---
Diff: https://github.com/kamailio/kamailio/commit/3f9210fc23840560c8fe33ef26b537a…
Patch: https://github.com/kamailio/kamailio/commit/3f9210fc23840560c8fe33ef26b537a…
---
diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md
index 9289eec2de..dac53f6d61 100644
--- a/.github/CONTRIBUTING.md
+++ b/.github/CONTRIBUTING.md
@@ -104,8 +104,15 @@ by the commit, for example:
* `modname`: support for foo rfc extension
* `usrloc`: support for gruu rfc extension
* `lib`: srutils - critical bug fix for abc case
+ * `etc`: kamailio.cfg - added core reply route block
+ * `misc`: examples/kemi lua - added debug callback function
* `kamctl`: added support for management of module xyz
+It is acceptable to use slightly different formats, like `etc/kamailio.cfg: ...`
+instead of `etc: kamailio.cfg - ...` or `modules/usrloc: ...` instead of
+`usrloc: ...`, the important aspect is to indicate the component where the
+changes were done.
+
At the end of the first line some CI flags can be added. Available at this
moment:
@@ -164,7 +171,7 @@ dialplan: basic safety for concurrent rpc reload
#### Commit Message Examples ####
- * change to usrloc module from modules
+ * changes to usrloc module from modules
```
usrloc: fixed name conflict
@@ -173,7 +180,7 @@ usrloc: fixed name conflict
with the usr_avp.h version
```
- * change to core
+ * changes to core
```
core: loadpath can now use a list of directories
@@ -183,6 +190,15 @@ core: loadpath can now use a list of directories
First match wins (e.g. for loadmodule "textops" if
modules/textops.so or modules/textops/textops.so exists, it will
be loaded and the search will stop).
+```
+
+ * changes to `etc/kamailio.cfg` file
+
+```
+etc: kamailio.cfg - set load_backends to 1 for permissions module
+
+- the config uses only address table
+
```
#### See Also ####