eclipse-bluechi / bluechi

Eclipse BlueChi is a systemd service controller intended for multi-node environments with a predefined number of nodes and with a focus on highly regulated ecosystems such as those requiring functional safety.
https://bluechi.readthedocs.io/en/latest/
GNU Lesser General Public License v2.1
130 stars 37 forks source link

Fix to get peer ip address #905

Closed dofmind closed 3 months ago

dofmind commented 3 months ago

If we try to read the IP address from a struct sockaddr_in while getpeername() filled it with struct sockaddr_in6 information, we are actually reading the sin6_flowinfo part of the struct sockaddr_in6. That flow information is usually zero, unless the connection is explicitely flagged with a flow ID. So we would read a zeroed IP address.

Reference: https://stackoverflow.com/a/25640794

AS-IS

root@42dot-ak7:~# bluechictl status
NODE                          | STATE     | IP             | LAST SEEN
==========================================================================================
ak7_master_main               | online    | 0.0.0.0        | now
ak7_master_sub                | online    | 0.0.0.0        | now

TO-BE

root@42dot-ak7:~# bluechictl status
NODE                          | STATE     | IP                      | LAST SEEN
==========================================================================================
ak7_master_main               | online    | ::ffff:192.168.16.103   | now
ak7_master_sub                | online    | ::ffff:192.168.16.104   | now
coveralls commented 3 months ago

Coverage Status

coverage: 85.15% (+0.07%) from 85.084% when pulling 7271c8898c1d3729d88a2e8e34c75b0ad3150f04 on dofmind:fix-to-get-peer-ip-address into 88afc8fea761434d5f7fba855f2024af83182a44 on eclipse-bluechi:main.