Add ifdef for synology around synology-only code in Linux Ethernet tap.

This commit is contained in:
Adam Ierymenko 2017-03-08 16:12:54 -08:00
parent ed4f84cc57
commit 9b001823f6
2 changed files with 7 additions and 3 deletions

View file

@ -220,6 +220,7 @@ static bool ___removeIp(const std::string &_dev,const InetAddress &ip)
} }
} }
#ifdef __SYNOLOGY__
bool LinuxEthernetTap::addIpSyn(std::vector<InetAddress> ips) bool LinuxEthernetTap::addIpSyn(std::vector<InetAddress> ips)
{ {
// Here we fill out interface config (ifcfg-dev) to prevent it from being killed // Here we fill out interface config (ifcfg-dev) to prevent it from being killed
@ -233,14 +234,14 @@ bool LinuxEthernetTap::addIpSyn(std::vector<InetAddress> ips)
setenv("PATH", "/sbin:/bin:/usr/sbin:/usr/bin", 1); 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 // can properly enumerate address/netmask combinations in the ifcfg-dev file
for(int i=0; i<ips.size(); i++) { for(int i=0; i<(int)ips.size(); i++) {
if (ips[i].isV4()) if (ips[i].isV4())
ip4_tot++; ip4_tot++;
else else
ip6_tot++; ip6_tot++;
} }
// Assemble and write contents of ifcfg-dev file // Assemble and write contents of ifcfg-dev file
for(int i=0; i<ips.size(); i++) { for(int i=0; i<(int)ips.size(); i++) {
if (ips[i].isV4()) { if (ips[i].isV4()) {
std::string numstr4 = ip4_tot > 1 ? std::to_string(ip4) : ""; std::string numstr4 = ip4_tot > 1 ? std::to_string(ip4) : "";
cfg_contents += "\nIPADDR"+numstr4+"="+ips[i].toIpString() cfg_contents += "\nIPADDR"+numstr4+"="+ips[i].toIpString()
@ -256,7 +257,7 @@ bool LinuxEthernetTap::addIpSyn(std::vector<InetAddress> ips)
} }
OSUtils::writeFile(filepath.c_str(), cfg_contents.c_str(), cfg_contents.length()); OSUtils::writeFile(filepath.c_str(), cfg_contents.c_str(), cfg_contents.length());
// Finaly, add IPs // Finaly, add IPs
for(int i=0; i<ips.size(); i++){ for(int i=0; i<(int)ips.size(); i++){
if (ips[i].isV4()) if (ips[i].isV4())
::execlp("ip","ip","addr","add",ips[i].toString().c_str(),"broadcast",ips[i].broadcast().toIpString().c_str(),"dev",_dev.c_str(),(const char *)0); ::execlp("ip","ip","addr","add",ips[i].toString().c_str(),"broadcast",ips[i].broadcast().toIpString().c_str(),"dev",_dev.c_str(),(const char *)0);
else else
@ -270,6 +271,7 @@ bool LinuxEthernetTap::addIpSyn(std::vector<InetAddress> ips)
} }
return true; return true;
} }
#endif // __SYNOLOGY__
bool LinuxEthernetTap::addIp(const InetAddress &ip) bool LinuxEthernetTap::addIp(const InetAddress &ip)
{ {

View file

@ -52,7 +52,9 @@ public:
void setEnabled(bool en); void setEnabled(bool en);
bool enabled() const; bool enabled() const;
bool addIp(const InetAddress &ip); bool addIp(const InetAddress &ip);
#ifdef __SYNOLOGY__
bool addIpSyn(std::vector<InetAddress> ips); bool addIpSyn(std::vector<InetAddress> ips);
#endif
bool removeIp(const InetAddress &ip); bool removeIp(const InetAddress &ip);
std::vector<InetAddress> ips() const; std::vector<InetAddress> ips() const;
void put(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len); void put(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len);