summaryrefslogtreecommitdiff
path: root/osdep
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2017-05-19 14:00:08 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2017-05-19 14:00:08 -0700
commit99e2098a48c1d3108ce5d6034b60d25f33195bd7 (patch)
treee7be6aeff6438534b0ff203cf32d75c1b1b30ef6 /osdep
parent5fc1c1de2874673f2c07cae48c632a5eb9b94fb8 (diff)
downloadinfinitytier-99e2098a48c1d3108ce5d6034b60d25f33195bd7.tar.gz
infinitytier-99e2098a48c1d3108ce5d6034b60d25f33195bd7.zip
Add a way to specify a different interface prefix (for internal use mostly).
Diffstat (limited to 'osdep')
-rw-r--r--osdep/LinuxEthernetTap.cpp25
1 files changed, 18 insertions, 7 deletions
diff --git a/osdep/LinuxEthernetTap.cpp b/osdep/LinuxEthernetTap.cpp
index 6a3ac4cb..b3160422 100644
--- a/osdep/LinuxEthernetTap.cpp
+++ b/osdep/LinuxEthernetTap.cpp
@@ -48,6 +48,7 @@
#include <algorithm>
#include <utility>
+#include <string>
#include "../node/Constants.hpp"
#include "../node/Utils.hpp"
@@ -97,6 +98,22 @@ LinuxEthernetTap::LinuxEthernetTap(
struct ifreq ifr;
memset(&ifr,0,sizeof(ifr));
+ // Linux supports arbitrary device naming -- this isn't available on other platforms so just use a simple hack for it
+#ifdef __SYNOLOGY__
+ int devno = 50;
+#else
+ int devno = 0;
+#endif
+ std::string devicepfx;
+ OSUtils::readFile((_homePath + ZT_PATH_SEPARATOR_S + "devicepfx").c_str(),devicepfx);
+ if (devicepfx.length() == 0) {
+#ifdef __SYNOLOGY__
+ devicepfx = "eth";
+#else
+ devicepfx = "zt";
+#endif
+ }
+
// Try to recall our last device name, or pick an unused one if that fails.
std::map<std::string,std::string> globalDeviceMap;
FILE *devmapf = fopen((_homePath + ZT_PATH_SEPARATOR_S + "devicemap").c_str(),"r");
@@ -124,14 +141,8 @@ LinuxEthernetTap::LinuxEthernetTap(
recalledDevice = (stat(procpath,&sbuf) != 0);
}
if (!recalledDevice) {
- int devno = 0;
do {
-#ifdef __SYNOLOGY__
- devno+=50; // Arbitrary number to prevent interface name conflicts
- Utils::snprintf(ifr.ifr_name,sizeof(ifr.ifr_name),"eth%d",devno++);
-#else
- Utils::snprintf(ifr.ifr_name,sizeof(ifr.ifr_name),"zt%d",devno++);
-#endif
+ Utils::snprintf(ifr.ifr_name,sizeof(ifr.ifr_name),"%s%d",devicepfx.c_str(),devno++);
Utils::snprintf(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
}