<!-- Kamailio Project uses GitHub Issues only for bugs in the code or feature requests. Please use this template only for bug reports.
If you have questions about using Kamailio or related to its configuration file, ask on sr-users mailing list:
* https://lists.kamailio.org/mailman3/postorius/lists/sr-users.lists.kamailio....
If you have questions about developing extensions to Kamailio or its existing C code, ask on sr-dev mailing list:
* https://lists.kamailio.org/mailman3/postorius/lists/sr-dev.lists.kamailio.or...
Please try to fill this template as much as possible for any issue. It helps the developers to troubleshoot the issue.
Note that an issue report may be closed automatically after about 2 months if there is no interest from developers or community users on pursuing it, being considered expired. In such case, it can be reopened by writing a comment that includes the token `/notexpired`. About two weeks before considered expired, the issue is marked with the label `stale`, trying to notify the submitter and everyone else that might be interested in it. To remove the label `stale`, write a comment that includes the token `/notstale`. Also, any comment postpone the `expire` timeline, being considered that there is interest in pursuing the issue.
If there is no content to be filled in a section, the entire section can be removed.
You can delete the comments from the template sections when filling.
You can delete next line and everything above before submitting (it is a comment). -->
### Description
When starting Kam inside a docker container and the `auto_bind_ipv6` option is enabled, kam fails to start, see below for error logs.
Instead, inside the very same container, by executing it from a shell, it works. The difference is that starting from the entrypoint kam has pid 1, while starting from a shell as a different pid.
### Troubleshooting
#### Reproduction
Start kamailio inside a docker container,with network=host and the `auto_bind_ipv6` option enabled.
#### Log Messages
<!-- Check the syslog file and if there are relevant log messages printed by Kamailio, add them next, or attach to issue, or provide a link to download them (e.g., to a pastebin site). -->
``` 2025-01-02T15:58:29.655278523Z 0(1) DEBUG: <core> [core/socket_info.c:1764]: add_interfaces(): If: lo Fam: 2 Flg: 10049 Adr: 127.0.0.1 2025-01-02T15:58:29.655282371Z 0(1) DEBUG: <core> [core/socket_info.c:1764]: add_interfaces(): If: eth0 Fam: 2 Flg: 11043 Adr: 188.34.182.80 2025-01-02T15:58:29.655286664Z 0(1) DEBUG: <core> [core/socket_info.c:1764]: add_interfaces(): If: docker0 Fam: 2 Flg: 1003 Adr: 172.17.0.1 2025-01-02T15:58:29.655290864Z 0(1) DEBUG: <core> [core/socket_info.c:1764]: add_interfaces(): If: br-1653739d678f Fam: 2 Flg: 11043 Adr: 172.18.0.1 2025-01-02T15:58:29.655295002Z 0(1) DEBUG: <core> [core/socket_info.c:1764]: add_interfaces(): If: br-kamnet Fam: 2 Flg: 11043 Adr: 172.23.42.1 2025-01-02T15:58:29.655299578Z 0(1) ERROR: <core> [core/socket_info.c:1349]: nl_bound_sock(): could not bind NETLINK sock to sockaddr_nl 2025-01-02T15:58:29.655303602Z 0(1) ERROR: <core> [core/socket_info.c:1666]: add_interfaces_via_netlink(): Could not get network interface list 2025-01-02T15:58:29.655482917Z 0(1) ERROR: <core> [core/socket_info.c:1789]: fix_hostname(): could not resolve 'matteo-ord-devel' 2025-01-02T15:58:29.655515080Z 0(1) ERROR: <core> [core/socket_info.c:2392]: fix_all_socket_lists(): fix_socket_list udp failed 2025-01-02T15:58:29.655519918Z failed to initialize list addresses ```
### Possible Solutions
I think that it boils down to the function [nl_bound_sock](https://github.com/kamailio/kamailio/blob/master/src/core/socket_info.c#L137...) function, which sets the netlink struct Port ID with `getpid()` ( https://github.com/kamailio/kamailio/blob/master/src/core/socket_info.c#L139... ).
For some reason this does not work when kam is forking from pid 1.
According to [man 7 netlink](https://man7.org/linux/man-pages/man7/netlink.7.html) should be safe to set that pid to 0, and let the kernel assign one, since if assigned from the process, it must guarantee that is unique if when multiple sockets are requested.
I've tried to set that port id to `0` and works correctly: ```diff diff --git a/src/core/socket_info.c b/src/core/socket_info.c index 2557a83b1e..662a3741c2 100644 --- a/src/core/socket_info.c +++ b/src/core/socket_info.c @@ -1343,7 +1343,7 @@ static int nl_bound_sock(void) bzero(&la, sizeof(la)); la.nl_family = AF_NETLINK; la.nl_pad = 0; - la.nl_pid = getpid(); + la.nl_pid = 0; la.nl_groups = 0; if(bind(sock, (struct sockaddr *)&la, sizeof(la)) < 0) { LM_ERR("could not bind NETLINK sock to sockaddr_nl\n"); ```
### Additional Information
* **Kamailio Version** - output of `kamailio -v`
5.8.4
* **Operating System**:
<!-- Details about the operating system, the type: Linux (e.g.,: Debian 8.4, Ubuntu 16.04, CentOS 7.1, ...), MacOS, xBSD, Solaris, ...; Kernel details (output of `lsb_release -a` and `uname -a`) -->
Docker container based on ubuntu noble.
Closed #4094 as completed.
Thanks for reporting and suggested fix. A commit has been pushed to git master branch and it will be backported for the next 5.8.x release.