#### 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 - [x] Related to issue #4315
#### Description Added a function to check the flow token. Useful to make sure the client TCP connection is alive. You can view, comment on, or merge this pull request online at:
https://github.com/kamailio/kamailio/pull/4449
-- Commit Summary --
* outbound: added check_flow_token function * outbound: docbook - fixed 'Attribute "xmlns:xi" must be declared for element type' * outbound: fixed xml validation errors * outbound: added check_flow_token documentation
-- File Changes --
M src/modules/outbound/doc/outbound.xml (3) M src/modules/outbound/doc/outbound_admin.xml (78) M src/modules/outbound/outbound_mod.c (149)
-- Patch Links --
https://github.com/kamailio/kamailio/pull/4449.patch https://github.com/kamailio/kamailio/pull/4449.diff
@sergey-safarov pushed 1 commit.
c9fe21b3c22b9d483f3a598e5c93c345c27dca62 outbound: added check_flow_token documentation
@henningw commented on this pull request.
Thanks for the PR, just a few smaller remarks from my side.
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding='ISO-8859-1'?> -<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" +<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
Why you changed from book to chapter type here? Type book is used in 99% of all places.
@@ -6,6 +6,9 @@
<!ENTITY % docentities SYSTEM "../../../../doc/docbook/entities.xml"> %docentities;
+<!ENTITY % xinclude SYSTEM "http://www.docbook.org/xml/4.4/xinclude.mod" >
Why you added this? Its not used elsewhere.
@@ -503,3 +518,137 @@ int bind_ob(struct ob_binds *pxb)
return 0; } + +/*! + * \brief Check if URI is myself + * \param _host host + * \param _port port + * \return 0 if the URI is not myself, 1 otherwise + */ +static inline int is_myself(sip_uri_t *_puri)
More a note - it might make sense to move this to the core, or to expose it with the RR module API, as its duplicated in some modules already. Could be also done later if necessary.
+ if(ret == 1) { + /* match on host:port, but if gruu, then fail */ + if(_puri->gr.s != NULL) + return 0; + } + + return ret; +} + +/*! + * \brief Parse the message and find first occurrence of Route header field. + * \param _m SIP message + * \return -1 or -2 on a parser error, 0 if there is a Route HF and 1 if there is no Route HF + */ +static inline int find_first_route(struct sip_msg *_m)
More a note - it might make sense to move this to the core, or to expose it with the RR module API, as its duplicated in some modules already. Could be also done later if necessary.
return CHECK_FLOW_ERROR_URI_NOT_MYSELF;
+ } + + + LM_DBG("topmost route URI: '%.*s' is me\n", uri.len, ZSW(uri.s)); + ret = decode_flow_token(msg, &rcv, puri.user); + + if(ret == -2) { + LM_DBG("no flow token found\n"); + return CHECK_FLOW_ERROR_NO_FLOW_TOKEN; + } else if(ret == -1) { + LM_DBG("failed to decode flow token\n"); + return CHECK_FLOW_ERROR_DECODE; + } else if(rcv->proto == PROTO_TCP || rcv->proto == PROTO_TLS + || rcv->proto == PROTO_WS || rcv->proto == PROTO_WSS) { + tcp_connection_t *con =
Please move variable initialization to the beginning of the function.
@sergey-safarov commented on this pull request.
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding='ISO-8859-1'?> -<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" +<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
I use `Oxygen XML Editor` for XML validation and hi generatesan error
E [Xerces] Document root element "chapter", must match DOCTYPE root "book".
Please check the example https://tdg.docbook.org/tdg/5.0/ch02 Here you can find. <img width="664" height="270" alt="image" src="https://github.com/user-attachments/assets/39b17f72-4b0f-4cac-b59d-daf73ac0f495" /> When used in this form, the XML validator does not claim.
@sergey-safarov commented on this pull request.
@@ -6,6 +6,9 @@
<!ENTITY % docentities SYSTEM "../../../../doc/docbook/entities.xml"> %docentities;
+<!ENTITY % xinclude SYSTEM "http://www.docbook.org/xml/4.4/xinclude.mod" >
XML validator reporting error
E [Xerces] Attribute "xmlns:xi" must be declared for element type "book".
I think this is well documented at https://www.oxygenxml.com/doc/versions/27.1/ug-author/topics/including-docum...
@sergey-safarov commented on this pull request.
@@ -503,3 +518,137 @@ int bind_ob(struct ob_binds *pxb)
return 0; } + +/*! + * \brief Check if URI is myself + * \param _host host + * \param _port port + * \return 0 if the URI is not myself, 1 otherwise + */ +static inline int is_myself(sip_uri_t *_puri)
I'm fine with using the core function.
@sergey-safarov commented on this pull request.
+ if(ret == 1) { + /* match on host:port, but if gruu, then fail */ + if(_puri->gr.s != NULL) + return 0; + } + + return ret; +} + +/*! + * \brief Parse the message and find first occurrence of Route header field. + * \param _m SIP message + * \return -1 or -2 on a parser error, 0 if there is a Route HF and 1 if there is no Route HF + */ +static inline int find_first_route(struct sip_msg *_m)
I'm fine with using the core function. Could core developers create these core functions and then we will use in this PR.
@sergey-safarov pushed 4 commits.
6362e8ce3ac149486649463be4de6f484f64041a outbound: added check_flow_token function 033c972bf46c94be6b3da02b25bbb394ceeb6f47 outbound: docbook - fixed 'Attribute "xmlns:xi" must be declared for element type' ef2c1159952bf85d1fbdd9a11b01808be3504476 outbound: fixed xml validation errors 6b005500deaf930a7b58f9cce135910d73d30d9e outbound: added check_flow_token documentation
@sergey-safarov commented on this pull request.
return CHECK_FLOW_ERROR_URI_NOT_MYSELF;
+ } + + + LM_DBG("topmost route URI: '%.*s' is me\n", uri.len, ZSW(uri.s)); + ret = decode_flow_token(msg, &rcv, puri.user); + + if(ret == -2) { + LM_DBG("no flow token found\n"); + return CHECK_FLOW_ERROR_NO_FLOW_TOKEN; + } else if(ret == -1) { + LM_DBG("failed to decode flow token\n"); + return CHECK_FLOW_ERROR_DECODE; + } else if(rcv->proto == PROTO_TCP || rcv->proto == PROTO_TLS + || rcv->proto == PROTO_WS || rcv->proto == PROTO_WSS) { + tcp_connection_t *con =
done
@ivanuschak commented on this pull request.
+int check_flow_token(struct sip_msg *msg) +{ + struct hdr_field *hdr; + struct sip_uri puri; + rr_t *rt; + str uri; + int ret; + struct receive_info *rcv = NULL; + tcp_connection_t *con = NULL; + + switch(find_first_route(msg)) { + case -1: + LM_DBG("there is no Route HF\n"); + return CHECK_FLOW_NO_ROUTE_HEADER; + break;
please remove, this `break` is not needed as well as the `bread` on 601 line
@ivanuschak commented on this pull request.
return 1;
+ } + } +} + +int check_flow_token(struct sip_msg *msg) +{ + struct hdr_field *hdr; + struct sip_uri puri; + rr_t *rt; + str uri; + int ret; + struct receive_info *rcv = NULL; + tcp_connection_t *con = NULL; + + switch(find_first_route(msg)) {
please check `find_first_route` function implementation. It returns 4 values: -2, -1, 0, 1. The value `1` is returned when no route header found. Service crashes when execution goes over this function and `sip_msg` does not contain Route header. Need to add `1` in the switch. Please fix.
@sergey-safarov pushed 4 commits.
63cf15ec342f3e9e84b6d40fc912983dcda9b6c4 outbound: added check_flow_token function 5bf437f7c55fc41b1782fb5d240c30e03b308919 outbound: docbook - fixed 'Attribute "xmlns:xi" must be declared for element type' 9e27057a51ec4816257492bb9ab1dcd22a3249d0 outbound: fixed xml validation errors 97b43533c3f80969c4d7c99dfd8993af7d1c5f6b outbound: added check_flow_token documentation
@sergey-safarov commented on this pull request.
+int check_flow_token(struct sip_msg *msg) +{ + struct hdr_field *hdr; + struct sip_uri puri; + rr_t *rt; + str uri; + int ret; + struct receive_info *rcv = NULL; + tcp_connection_t *con = NULL; + + switch(find_first_route(msg)) { + case -1: + LM_DBG("there is no Route HF\n"); + return CHECK_FLOW_NO_ROUTE_HEADER; + break;
done
@sergey-safarov commented on this pull request.
return 1;
+ } + } +} + +int check_flow_token(struct sip_msg *msg) +{ + struct hdr_field *hdr; + struct sip_uri puri; + rr_t *rt; + str uri; + int ret; + struct receive_info *rcv = NULL; + tcp_connection_t *con = NULL; + + switch(find_first_route(msg)) {
done
miconda left a comment (kamailio/kamailio#4449)
I added the functions (with different names) to core with the commits 521c974a200569b39f48b397853f50299d06ae7e and d11a33dc80431b69a3e7f29e1b00071ca24b5f04 . I will update rr module to use them.
@sergey-safarov pushed 4 commits.
03bd78693cf7d220f3ae463900dde29696a6a05f outbound: added check_flow_token function f8998a4ad4544b4499b48ad35d47c14dc040025a outbound: docbook - fixed 'Attribute "xmlns:xi" must be declared for element type' 15bd0d437c4164726b8fb3af419614f73339ce8c outbound: fixed xml validation errors 368656cff011137b601f2c6356f473ae4c805647 outbound: added check_flow_token documentation
@sergey-safarov commented on this pull request.
+ if(ret == 1) { + /* match on host:port, but if gruu, then fail */ + if(_puri->gr.s != NULL) + return 0; + } + + return ret; +} + +/*! + * \brief Parse the message and find first occurrence of Route header field. + * \param _m SIP message + * \return -1 or -2 on a parser error, 0 if there is a Route HF and 1 if there is no Route HF + */ +static inline int find_first_route(struct sip_msg *_m)
done
@sergey-safarov commented on this pull request.
@@ -503,3 +518,137 @@ int bind_ob(struct ob_binds *pxb)
return 0; } + +/*! + * \brief Check if URI is myself + * \param _host host + * \param _port port + * \return 0 if the URI is not myself, 1 otherwise + */ +static inline int is_myself(sip_uri_t *_puri)
done
miconda left a comment (kamailio/kamailio#4449)
The description of the commit lists return 0, which should not be done by a module config function because it stops config execution -- this as a note, because it seems the code is returning negative and positive int values. But I would suggest to add explicit values to the enum fields, not only the -7 and 1, it should be safer in the future and easier to understand when looking at the code, avoiding shifting values when a new field might be added:
``` typedef enum check_flow_retcode { CHECK_FLOW_ERROR_HEADERS_PARSE = -7, CHECK_FLOW_ERROR_ROUTE_PARSE, CHECK_FLOW_EXPIRED, CHECK_FLOW_NO_TCP_CONNECTION, CHECK_FLOW_ERROR_DECODE, CHECK_FLOW_ERROR_NO_FLOW_TOKEN, CHECK_FLOW_ERROR_URI_NOT_MYSELF, CHECK_FLOW_NO_ROUTE_HEADER = 1, CHECK_FLOW_SUCCESS } check_flow_retcode_t; ```
Then, in my opinion CHECK_FLOW_NO_ROUTE_HEADER belongs better to the negative/failure range (false in native scripting), and have only CHECK_FLOW_SUCCESS as positive/success (true).
@sergey-safarov pushed 4 commits.
2c726ff6af5693c219848b4363b7fd18b8e47266 outbound: added check_flow_token function 5eecf06aec691b34aa499106849a7e28a9748e17 outbound: docbook - fixed 'Attribute "xmlns:xi" must be declared for element type' bfb73f730b018853bae69b88e29e95a271cb6bc0 outbound: fixed xml validation errors ddd4e761e0040b234a5a0db93d5f902dbfdd90b1 outbound: added check_flow_token documentation
sergey-safarov left a comment (kamailio/kamailio#4449)
@miconda I have updated the ENUM definition as proposed in the previous message, and updated description the XML documentation. Also fixed the commit description.
@sergey-safarov pushed 1 commit.
98061cea0e1b81e79c1ad140334e8e4de3c7a3fa outbound: added check_flow_token documentation
sergey-safarov left a comment (kamailio/kamailio#4449)
Maybe the `check_flowtoken` function name is more preferred than `check_flow_token`?
miconda left a comment (kamailio/kamailio#4449)
Merging it, thanks!
Merged #4449 into master.