Skip to content

Commit

Permalink
RTPS Domain hostid part of the GUID match first interface IP
Browse files Browse the repository at this point in the history
Because of the code [here](https://github.com/eProsima/Fast-RTPS/blob/f6ebf154a97089136c4906de11f535969708f2a0/src/cpp/rtps/RTPSDomain.cpp#L113), the RTPS Domain GUID can potentially be not unique between multiple participant hosted on different computer. This happens because the host ID component is initialized with eProsima magic number (0x010f) and the last two digit of the IPv4 address of the first interface enumerated by `getifaddrs`.

On some systems where there are several network interfaces, this scheme is not sufficient for generating a mostly unique hostid to be used for the RTPS Domain and collision can happen in the case where the first interface enumerated is an interface used by the system in isolation with the actual network. In addition, the `appId (the process ID running the stack) is only unique within the computer itself and does not provide enough uniqueness especially when the process is started as part of a systemd job on boot.

This fix generates a MD5 sum of all IPv4 addresses for all interfaces, then "folds" that 16 bytes MD5 sum into a 16 bits value to be used as the lower two bytes of the hostid field. Doing it this way provides more guarantee that the field will be unique across multiple identical systems.

issue: #456
  • Loading branch information
guillaumeautran committed Apr 11, 2019
1 parent d155904 commit 454c038
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/cpp/rtps/RTPSDomain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <fastrtps/utils/IPLocator.h>
#include <fastrtps/utils/eClock.h>
#include <fastrtps/utils/System.h>
#include <fastrtps/utils/md5.h>

#include <fastrtps/rtps/writer/RTPSWriter.h>
#include <fastrtps/rtps/reader/RTPSReader.h>
Expand Down Expand Up @@ -106,17 +107,28 @@ RTPSParticipant* RTPSDomain::createParticipant(
GuidPrefix_t guidP;
LocatorList_t loc;
IPFinder::getIP4Address(&loc);

guidP.value[0] = c_VendorId_eProsima[0];
guidP.value[1] = c_VendorId_eProsima[1];

if(loc.size()>0)
{
guidP.value[0] = c_VendorId_eProsima[0];
guidP.value[1] = c_VendorId_eProsima[1];
guidP.value[2] = loc.begin()->address[14];
guidP.value[3] = loc.begin()->address[15];
MD5 md5;
for(auto& l : loc)
{
md5.update(l.address, sizeof(l.address));
}
md5.finalize();
uint16_t hostid = 0;
for(size_t i = 0; i < sizeof(md5.digest); i += 2)
{
hostid ^= ((md5.digest[i] << 8) | md5.digest[i+1]);
}
guidP.value[2] = octet(hostid);
guidP.value[3] = octet(hostid >> 8);
}
else
{
guidP.value[0] = c_VendorId_eProsima[0];
guidP.value[1] = c_VendorId_eProsima[1];
guidP.value[2] = 127;
guidP.value[3] = 1;

Expand Down

0 comments on commit 454c038

Please sign in to comment.