<!-- 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
- [X] Related to issue #2984
#### Description
A new option to "listen" has been added called "virtual". This sets a flag on the listening socket to modify the behaviour of grep_sock_info. When this flag is set, grep_sock_info will only consider the listening IP a match if the IP is found in the system's current list of local IP addresses. If the IP is not currently local, then the matching IP is ignored.
If the virtual flag is not set on the socket then existing behaviour used instead.
This feature is intended for scenarios where you have two Kamailio nodes in active/active setup, with virtual IPs, where you need to be able to listen on a virtual IP but it may not always be active locally. With this flag applied to a `listen=` socket, Kamailio will only consider traffic destined to this IP local, when the IP is actually active on the system, and other times the match is ignored.
You can view, comment on, or merge this pull request online at:
https://github.com/kamailio/kamailio/pull/2985
-- Commit Summary --
* core: listen can now have a "virtual" flag to check for nonlocal floating IPs.
* etc: kamailio.cfg - added example use of listen's new virtual flag.
* core: Added virtual flag to output of core.sockets_list
* corex: Added virtual flag to output of "corex.list_sockets"
* ims_ipsec_pcscf: Added virtual flag to output of sockets list.
-- File Changes --
M etc/kamailio.cfg (2)
M src/core/cfg.lex (2)
M src/core/cfg.y (83)
M src/core/core_cmd.c (10)
M src/core/ip_addr.h (1)
M src/core/socket_info.c (85)
M src/modules/corex/corex_rpc.c (5)
M src/modules/ims_ipsec_pcscf/ims_ipsec_pcscf_mod.c (8)
-- Patch Links --
https://github.com/kamailio/kamailio/pull/2985.patchhttps://github.com/kamailio/kamailio/pull/2985.diff
--
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/pull/2985
You are receiving this because you are subscribed to this thread.
Message ID: <kamailio/kamailio/pull/2985(a)github.com>
Module: kamailio
Branch: master
Commit: 3e7d5ed34033067377ed9034e4ec49be444ca6fe
URL: https://github.com/kamailio/kamailio/commit/3e7d5ed34033067377ed9034e4ec49b…
Author: Rhys Hanrahan <rhys(a)nexusone.com.au>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2022-01-07T12:27:25+01:00
core: Updated check_local_addresses to use getifaddrs
Changed virtual socket code to use getifaddrs instead of gethostbyname as this avoids lookups against the hosts file, which causes incorrect results.
---
Modified: src/core/socket_info.c
---
Diff: https://github.com/kamailio/kamailio/commit/3e7d5ed34033067377ed9034e4ec49b…
Patch: https://github.com/kamailio/kamailio/commit/3e7d5ed34033067377ed9034e4ec49b…
---
diff --git a/src/core/socket_info.c b/src/core/socket_info.c
index 8ee6cd0b32..afb1dd5603 100644
--- a/src/core/socket_info.c
+++ b/src/core/socket_info.c
@@ -575,8 +575,8 @@ struct socket_info** get_sock_info_list(unsigned short proto)
*/
static int check_local_addresses(struct socket_info* si)
{
- struct hostent* he;
- struct utsname myname;
+ int match = 0;
+ struct ifaddrs *ifap, *ifa;
if (si == NULL) {
LM_ERR("Socket info is NULL. Returning no match.\n");
@@ -589,40 +589,41 @@ static int check_local_addresses(struct socket_info* si)
return 1;
}
- if (uname(&myname) <0){
- LM_ERR("Cannot determine hostname. Guessing a not local virtual IP.\n");
+ if (getifaddrs(&ifap) != 0) {
+ LM_ERR("getifaddrs failed. Assuming no match.\n");
return 0;
}
-
- //Should return a list of local IPs
- he = _resolvehost(myname.nodename);
- if (he == NULL) {
- LM_ERR("Cannot get list of local IPs. Guessing not a local virtual IP.\n");
- return 0;
- }
- char** paddrlist = he->h_addr_list;
- int i = 0;
- while (*paddrlist != NULL)
+
+ for (ifa = ifap; ifa; ifa = ifa->ifa_next)
{
+ /* skip if no IP addr associated with the interface */
+ if (ifa->ifa_addr==0)
+ continue;
+#ifdef AF_PACKET
+ /* skip AF_PACKET addr family since it is of no use later on */
+ if (ifa->ifa_addr->sa_family == AF_PACKET)
+ continue;
+#endif
struct ip_addr local_addr;
- hostent2ip_addr(&local_addr, he, i);
+ sockaddr2ip_addr(&local_addr, (struct sockaddr*)ifa->ifa_addr);
LM_DBG("Checking local address: %s\n", ip_addr2a(&local_addr));
if (ip_addr_cmp(&si->address, &local_addr)) {
- LM_DBG("Found matching local IP for virtual socket: %s\n", ip_addr2a(&local_addr));
- return 1;
+ match = 1;
+ LM_DBG("Found matching local IP %s for virtual socket %s\n", ip_addr2a(&local_addr), si->name.s);
+ break;
}
-
- i++;
- paddrlist++;
}
-
+ freeifaddrs(ifap);
//Default to not local if no match is found
- LM_DBG("No matching local IP found.\n");
- return 0;
+ if (!match) {
+ LM_DBG("No matching local IP found for socket %s.\n", si->name.s);
+ return 0;
+ } else {
+ return 1;
+ }
}
-
/* helper function for grep_sock_info
* params:
* host - hostname to compare with
Module: kamailio
Branch: master
Commit: e93640e6119e61a24d8c1f6d36b60c83b3573f90
URL: https://github.com/kamailio/kamailio/commit/e93640e6119e61a24d8c1f6d36b60c8…
Author: Rhys Hanrahan <rhys(a)nexusone.com.au>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2022-01-07T12:27:25+01:00
core: listen can now have a "virtual" flag to check for nonlocal floating IPs.
A new option to "listen" has been added called "virtual". This sets a flag on the listening socket to modify the behaviour of grep_sock_info.
When this flag is set, grep_sock_info will only consider the listening IP a match if the IP is found in the system's current list of
local IP addresses. If the IP is not currently local, then the matching IP is ignored.
If the virtual flag is not set on the socket then existing behaviour used instead.
This is useful in scenarios with an active/active cluster where Kamailio must know if a floating IP is currently local or not.
---
Modified: src/core/cfg.lex
Modified: src/core/cfg.y
Modified: src/core/ip_addr.h
Modified: src/core/socket_info.c
---
Diff: https://github.com/kamailio/kamailio/commit/e93640e6119e61a24d8c1f6d36b60c8…
Patch: https://github.com/kamailio/kamailio/commit/e93640e6119e61a24d8c1f6d36b60c8…
<!-- 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 -->
- [ ] Commit message has the format required by CONTRIBUTING guide
- [ ] Commits are split per component (core, individual modules, libs, utils, ...)
- [ ] 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)
- [ ] New feature (non-breaking change which adds new functionality)
- [x] 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
<!-- Describe your changes in detail -->
We faced an issue that tcp:close (timeout and reset) event routes don't execute in rare cases. Debugging and testing show that in the case when a connection is marked as BAD or write timeout etc our event routes don't execute.
I found that executing event routes is in the read function only. So in case when a connection is destroyed triggered by other reasons we don't have a notification about this.
I propose to do this in main file every time when we destroy connections. But in this case, we don't have I reason to destroy (timeout reset or EOF).
In our lab with these changes issue is gone. But sure this is just a concept.
You can view, comment on, or merge this pull request online at:
https://github.com/kamailio/kamailio/pull/2980
-- Commit Summary --
* tcpclose event_routes issue
-- File Changes --
M src/core/tcp_main.c (26)
M src/core/tcp_read.c (26)
-- Patch Links --
https://github.com/kamailio/kamailio/pull/2980.patchhttps://github.com/kamailio/kamailio/pull/2980.diff
--
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/pull/2980
You are receiving this because you are subscribed to this thread.
Message ID: <kamailio/kamailio/pull/2980(a)github.com>