From 7bca63322a7ab942ced7a57633086c3473317331 Mon Sep 17 00:00:00 2001 From: Ilya Evseev Date: Sun, 27 Aug 2023 18:17:24 +0300 Subject: [PATCH 1/2] Use /sbin/ip from iproute2 instead of ifconfig under Linux. --- src/tun.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/tun.cpp b/src/tun.cpp index 8bfeb58..0544242 100644 --- a/src/tun.cpp +++ b/src/tun.cpp @@ -76,8 +76,12 @@ Tun::Tun(const string *device, int mtu) cmdline << "netsh interface ipv4 set subinterface \"" << this->device << "\" mtu=" << mtu; winsystem(cmdline.str().data()); +#else +#ifdef LINUX + cmdline << "/sbin/ip link set " << this->device << " mtu " << mtu; #else cmdline << "/sbin/ifconfig " << this->device << " mtu " << mtu; +#endif if (system(cmdline.str().data()) != 0) syslog(LOG_ERR, "could not set tun device mtu"); #endif @@ -101,13 +105,15 @@ void Tun::setIp(uint32_t ip, uint32_t destIp) if (!tun_set_ip(fd, ip, ip & 0xffffff00, 0xffffff00)) syslog(LOG_ERR, "could not set tun device driver ip address: %s", tun_last_error()); -#elif LINUX +#else +#ifdef LINUX + cmdline << "/sbin/ip addr replace " << ips << "/24 dev " << device; +#elif defined(OLD_LINUX) cmdline << "/sbin/ifconfig " << device << " " << ips << " netmask 255.255.255.0"; - if (system(cmdline.str().data()) != 0) - syslog(LOG_ERR, "could not set tun device ip address"); #else cmdline << "/sbin/ifconfig " << device << " " << ips << " " << destIps << " netmask 255.255.255.255"; +#endif if (system(cmdline.str().data()) != 0) syslog(LOG_ERR, "could not set tun device ip address"); #endif From ea3f51c70274c49a4c3d4d09864bced41d2076c3 Mon Sep 17 00:00:00 2001 From: Ilya Evseev Date: Thu, 7 Sep 2023 05:20:10 +0300 Subject: [PATCH 2/2] tun.cpp: use /usr/sbin/ip instead of /sbin/ip https://www.freedesktop.org/wiki/Software/systemd/TheCaseForTheUsrMerge/ --- src/tun.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tun.cpp b/src/tun.cpp index 0544242..7d82851 100644 --- a/src/tun.cpp +++ b/src/tun.cpp @@ -78,7 +78,7 @@ Tun::Tun(const string *device, int mtu) winsystem(cmdline.str().data()); #else #ifdef LINUX - cmdline << "/sbin/ip link set " << this->device << " mtu " << mtu; + cmdline << "/usr/sbin/ip link set " << this->device << " mtu " << mtu; #else cmdline << "/sbin/ifconfig " << this->device << " mtu " << mtu; #endif @@ -107,7 +107,7 @@ void Tun::setIp(uint32_t ip, uint32_t destIp) syslog(LOG_ERR, "could not set tun device driver ip address: %s", tun_last_error()); #else #ifdef LINUX - cmdline << "/sbin/ip addr replace " << ips << "/24 dev " << device; + cmdline << "/usr/sbin/ip addr replace " << ips << "/24 dev " << device; #elif defined(OLD_LINUX) cmdline << "/sbin/ifconfig " << device << " " << ips << " netmask 255.255.255.0"; #else