Module: kamailio
Branch: master
Commit: 7acfe7723b4772ca45ce31ae98bf3d0b6948f50a
URL:
https://github.com/kamailio/kamailio/commit/7acfe7723b4772ca45ce31ae98bf3d0…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2024-09-30T15:43:42+02:00
core: socket info - do not use interface index as internal array index
- there are cases when the interface number is high, even if there are
only a few real network interfaces, which can result in inability to
listen on them
---
Modified: src/core/socket_info.c
---
Diff:
https://github.com/kamailio/kamailio/commit/7acfe7723b4772ca45ce31ae98bf3d0…
Patch:
https://github.com/kamailio/kamailio/commit/7acfe7723b4772ca45ce31ae98bf3d0…
---
diff --git a/src/core/socket_info.c b/src/core/socket_info.c
index c8782bc0b3f..4142ab17dce 100644
--- a/src/core/socket_info.c
+++ b/src/core/socket_info.c
@@ -1494,6 +1494,7 @@ static int build_iface_list(void)
char name[MAX_IF_LEN];
int is_link_local = 0;
int num = 0;
+ int ifidx = 0;
if(ifaces == NULL) {
if((ifaces = (struct idxlist *)pkg_malloc(
@@ -1621,31 +1622,42 @@ static int build_iface_list(void)
}
}
- if(index >= MAX_IFACE_NO) {
- LM_ERR("Invalid interface index returned: %d (n: %d) - skip\n",
- index, num);
- pkg_free(entry);
- continue;
+ for(ifidx = 0; ifidx < MAX_IFACE_NO; ifidx++) {
+ if(ifaces[ifidx].index == index) {
+ /* interface with same index already found */
+ break;
+ }
+ }
+ if(ifidx == MAX_IFACE_NO) {
+ if(num == MAX_IFACE_NO) {
+ LM_ERR("too many interfaces: %d (n: %d) - skipping\n",
+ index, num);
+ pkg_free(entry);
+ goto done;
+ }
+ ifidx = num;
+ num++;
}
- num++;
- if(strlen(ifaces[index].name) == 0 && strlen(name) > 0) {
- memcpy(ifaces[index].name, name, MAX_IF_LEN - 1);
- ifaces[index].name[MAX_IF_LEN - 1] = '\0';
+ if(strlen(ifaces[ifidx].name) == 0 && strlen(name) > 0) {
+ memcpy(ifaces[ifidx].name, name, MAX_IF_LEN - 1);
+ ifaces[ifidx].name[MAX_IF_LEN - 1] = '\0';
}
- ifaces[index].index = index;
+ ifaces[ifidx].index = index;
- if(ifaces[index].addresses == 0)
- ifaces[index].addresses = entry;
+ if(ifaces[ifidx].addresses == 0)
+ ifaces[ifidx].addresses = entry;
else {
- for(tmp = ifaces[index].addresses; tmp->next;
+ for(tmp = ifaces[ifidx].addresses; tmp->next;
tmp = tmp->next) /*empty*/
;
tmp->next = entry;
}
}
}
+
+done:
if(nl_sock > 0)
close(nl_sock);
/* the socket should be closed so we can bind again */