Loading src/network.cpp +21 −1 Changes for src/network.cpp: 21 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ #include <unistd.h> #include <fcntl.h> #include <net/if.h> #include <linux/ethtool.h> #include <linux/sockios.h> #include <arpa/inet.h> #include <sys/socket.h> #include <sys/ioctl.h> Loading Loading @@ -434,6 +436,20 @@ static std::string readSysfs(const std::string &ifname, const char *attr) { } // what the device is: "bond", "bridge", "wireguard" or "" // the driver of a network device as ethtool names it ("" if unknown) static std::string linkDriver(const std::string &ifname) { int fd = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0); if (fd < 0) return ""; struct ethtool_drvinfo info{}; info.cmd = ETHTOOL_GDRVINFO; struct ifreq ifr{}; std::strncpy(ifr.ifr_name, ifname.c_str(), IFNAMSIZ - 1); ifr.ifr_data = reinterpret_cast<char *>(&info); int r = ioctl(fd, SIOCETHTOOL, &ifr); ::close(fd); return r == 0 ? std::string(info.driver) : ""; } static std::string linkKind(const std::string &ifname) { std::error_code ec; const std::string sys = "/sys/class/net/" + ifname; Loading @@ -443,6 +459,8 @@ static std::string linkKind(const std::string &ifname) { std::string line; while (std::getline(uevent, line)) if (trim(line) == "DEVTYPE=wireguard") return "wireguard"; // a veth pair's end (containers: containerd, docker, nspawn) if (linkDriver(ifname) == "veth") return "veth"; return ""; } Loading Loading @@ -1236,7 +1254,9 @@ std::map<std::string, WireGuardPeerStatus> NetworkManager::wireGuardPeers(const } bool NetworkManager::deleteUnconfiguredLink(const std::string &ifname, std::string *err) { if (findNetDev(ifname) || !interfaceExists(ifname) || linkKind(ifname).empty()) { // a veth belongs to a container (containerd & co.), not to syslite std::string kind = interfaceExists(ifname) ? linkKind(ifname) : ""; if (findNetDev(ifname) || kind.empty() || kind == "veth") { if (err) *err = "no bond or bridge " + ifname; return false; } Loading Loading
src/network.cpp +21 −1 Changes for src/network.cpp: 21 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ #include <unistd.h> #include <fcntl.h> #include <net/if.h> #include <linux/ethtool.h> #include <linux/sockios.h> #include <arpa/inet.h> #include <sys/socket.h> #include <sys/ioctl.h> Loading Loading @@ -434,6 +436,20 @@ static std::string readSysfs(const std::string &ifname, const char *attr) { } // what the device is: "bond", "bridge", "wireguard" or "" // the driver of a network device as ethtool names it ("" if unknown) static std::string linkDriver(const std::string &ifname) { int fd = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0); if (fd < 0) return ""; struct ethtool_drvinfo info{}; info.cmd = ETHTOOL_GDRVINFO; struct ifreq ifr{}; std::strncpy(ifr.ifr_name, ifname.c_str(), IFNAMSIZ - 1); ifr.ifr_data = reinterpret_cast<char *>(&info); int r = ioctl(fd, SIOCETHTOOL, &ifr); ::close(fd); return r == 0 ? std::string(info.driver) : ""; } static std::string linkKind(const std::string &ifname) { std::error_code ec; const std::string sys = "/sys/class/net/" + ifname; Loading @@ -443,6 +459,8 @@ static std::string linkKind(const std::string &ifname) { std::string line; while (std::getline(uevent, line)) if (trim(line) == "DEVTYPE=wireguard") return "wireguard"; // a veth pair's end (containers: containerd, docker, nspawn) if (linkDriver(ifname) == "veth") return "veth"; return ""; } Loading Loading @@ -1236,7 +1254,9 @@ std::map<std::string, WireGuardPeerStatus> NetworkManager::wireGuardPeers(const } bool NetworkManager::deleteUnconfiguredLink(const std::string &ifname, std::string *err) { if (findNetDev(ifname) || !interfaceExists(ifname) || linkKind(ifname).empty()) { // a veth belongs to a container (containerd & co.), not to syslite std::string kind = interfaceExists(ifname) ? linkKind(ifname) : ""; if (findNetDev(ifname) || kind.empty() || kind == "veth") { if (err) *err = "no bond or bridge " + ifname; return false; } Loading