summaryrefslogtreecommitdiff
path: root/osdep/LinuxEthernetTap.cpp
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2018-04-25 06:41:44 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2018-04-25 06:41:44 -0700
commit05bfafbce8b00d9a99e6bf858f5c3d1645442952 (patch)
treee91f72b8af8208ec24c3c1acc0ea9875d6d2e994 /osdep/LinuxEthernetTap.cpp
parent9da79671976411072bbfd18ec1bb92507a0e63e2 (diff)
parentd32a26f780ce7222aa89af64abecf7044ce62327 (diff)
downloadinfinitytier-05bfafbce8b00d9a99e6bf858f5c3d1645442952.tar.gz
infinitytier-05bfafbce8b00d9a99e6bf858f5c3d1645442952.zip
Merge branch 'master' into edge
Diffstat (limited to 'osdep/LinuxEthernetTap.cpp')
-rw-r--r--osdep/LinuxEthernetTap.cpp27
1 files changed, 15 insertions, 12 deletions
diff --git a/osdep/LinuxEthernetTap.cpp b/osdep/LinuxEthernetTap.cpp
index 6ef42744..06bbbada 100644
--- a/osdep/LinuxEthernetTap.cpp
+++ b/osdep/LinuxEthernetTap.cpp
@@ -146,18 +146,21 @@ LinuxEthernetTap::LinuxEthernetTap(
OSUtils::ztsnprintf(procpath,sizeof(procpath),"/proc/sys/net/ipv4/conf/%s",ifr.ifr_name);
} while (stat(procpath,&sbuf) == 0); // try zt#++ until we find one that does not exist
#else
- char devno = 0;
+ uint64_t trial = 0; // incremented in the very unlikely event of a name collision with another network
do {
- uint64_t tmp2[2];
- tmp2[0] = Utils::hton(nwid);
- tmp2[1] = 0;
- char tmp3[17];
+ const uint64_t nwid40 = (nwid ^ (nwid >> 24)) + trial++;
+ uint8_t tmp2[5];
+ char tmp3[11];
+ tmp2[0] = (uint8_t)((nwid40 >> 32) & 0xff);
+ tmp2[1] = (uint8_t)((nwid40 >> 24) & 0xff);
+ tmp2[2] = (uint8_t)((nwid40 >> 16) & 0xff);
+ tmp2[3] = (uint8_t)((nwid40 >> 8) & 0xff);
+ tmp2[4] = (uint8_t)(nwid40 & 0xff);
tmp3[0] = 'z';
- tmp3[1] = 't' + (devno++);
- _base32_5_to_8(reinterpret_cast<const uint8_t *>(tmp2),tmp3 + 2);
- _base32_5_to_8(reinterpret_cast<const uint8_t *>(tmp2) + 5,tmp3 + 10);
- tmp3[15] = (char)0;
- memcpy(ifr.ifr_name,tmp3,16);
+ tmp3[1] = 't';
+ _base32_5_to_8(tmp2,tmp3 + 2);
+ tmp3[10] = (char)0;
+ memcpy(ifr.ifr_name,tmp3,11);
OSUtils::ztsnprintf(procpath,sizeof(procpath),"/proc/sys/net/ipv4/conf/%s",ifr.ifr_name);
} while (stat(procpath,&sbuf) == 0);
#endif
@@ -286,7 +289,7 @@ bool LinuxEthernetTap::addIpSyn(std::vector<InetAddress> ips)
if (cpid == 0) {
OSUtils::redirectUnixOutputs("/dev/null",(const char *)0);
setenv("PATH", "/sbin:/bin:/usr/sbin:/usr/bin", 1);
- // We must know if there is at least (one) of each protocol version so we
+ // We must know if there is at least (one) of each protocol version so we
// can properly enumerate address/netmask combinations in the ifcfg-dev file
for(int i=0; i<(int)ips.size(); i++) {
if (ips[i].isV4())
@@ -318,7 +321,7 @@ bool LinuxEthernetTap::addIpSyn(std::vector<InetAddress> ips)
if (ips[i].isV4())
::execlp("ip","ip","addr","add",ips[i].toString(iptmp),"broadcast",ips[i].broadcast().toIpString(iptmp2),"dev",_dev.c_str(),(const char *)0);
else
- ::execlp("ip","ip","addr","add",ips[i].toString(iptmp),"dev",_dev.c_str(),(const char *)0);
+ ::execlp("ip","ip","addr","add",ips[i].toString(iptmp),"dev",_dev.c_str(),(const char *)0);
}
::_exit(-1);
} else if (cpid > 0) {