Loading src/network.cpp +31 −2 Changes for src/network.cpp: 31 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -972,6 +972,7 @@ bool NetworkManager::deleteNetDev(const std::string &ifname, std::string *err) { unconfigureInterface(ifname); deleteLink(ifname); // its members are released with it } _createdLinks.erase(ifname); _stopped.erase(ifname); reloadConfigs(); // the member that got the addresses back has them at once, not only Loading @@ -989,6 +990,17 @@ bool NetworkManager::deleteNetDev(const std::string &ifname, std::string *err) { // kind or bond mode / STP setting (a bond's mode can't change while it has // members; its members are added again by the member configurations). void NetworkManager::applyNetDevs() { // devices syslite created whose .netdev is gone (e.g. an aborted // change put the files back): they go too for (auto it = _createdLinks.begin(); it != _createdLinks.end();) { if (findNetDev(*it)) { ++it; continue; } if (interfaceExists(*it)) { std::cout << "[syslite/net] " << *it << " has no configuration any more, deleting it" << std::endl; unconfigureInterface(*it); deleteLink(*it); } it = _createdLinks.erase(it); } for (auto &nd : _netdevs) { if (interfaceExists(nd.ifname)) { if (linkMatches(nd)) continue; Loading @@ -996,13 +1008,30 @@ void NetworkManager::applyNetDevs() { unconfigureInterface(nd.ifname); deleteLink(nd.ifname); } if (createLink(nd)) if (createLink(nd)) { _createdLinks.insert(nd.ifname); std::cout << "[syslite/net] Created " << nd.kind << " " << nd.ifname << " (" << nd.name << ".netdev)" << std::endl; else } else std::cerr << "[syslite/net] Cannot create " << nd.kind << " " << nd.ifname << std::endl; } } bool NetworkManager::deleteUnconfiguredLink(const std::string &ifname, std::string *err) { std::error_code ec; const std::string sys = "/sys/class/net/" + ifname; if (findNetDev(ifname) || !interfaceExists(ifname) || (!std::filesystem::exists(sys + "/bonding", ec) && !std::filesystem::exists(sys + "/bridge", ec))) { if (err) *err = "no bond or bridge " + ifname; return false; } std::cout << "[syslite/net] Deleting " << ifname << " (no configuration)" << std::endl; unconfigureInterface(ifname); _stopped.erase(ifname); _createdLinks.erase(ifname); if (!deleteLink(ifname)) { if (err) *err = "cannot delete " + ifname; return false; } return true; } bool NetworkManager::linkMatches(const NetDevConfig &nd) { std::error_code ec; const std::string sys = "/sys/class/net/" + nd.ifname; Loading src/network.h +5 −0 Changes for src/network.h: 5 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -147,6 +147,10 @@ namespace syslite { bool saveNetDev(const NetDevConfig &nd, const std::vector<std::string> &members, std::string *err); bool deleteNetDev(const std::string &ifname, std::string *err); void applyNetDevs(); // a bond or bridge device without a .netdev (left over, e.g. from an // aborted change): the device only is deleted; false if ifname // isn't such a device bool deleteUnconfiguredLink(const std::string &ifname, std::string *err); // Start listening for new network devices (netlink RTNLGRP_LINK) // Returns fd to poll in the main loop (-1 on failure) Loading Loading @@ -223,6 +227,7 @@ namespace syslite { std::map<std::string, std::vector<std::string>> _dnsByIf; // DNS servers per interface std::set<std::string> _configured; // interfaces configureInterface() set up std::set<std::string> _stopped; // interfaces stopped on request std::set<std::string> _createdLinks; // bonds/bridges created by applyNetDevs bool _resolvWritten = false; // resolv.yaml is ours once written int _monitorFd = -1; }; Loading src/syslite.cpp +5 −2 Changes for src/syslite.cpp: 5 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -509,8 +509,11 @@ namespace syslite { std::string why; if (op == m::DeleteNetDev) { if (!_network.findNetDev(name)) return Message::error(call, err::UnknownInterface, "no bond or bridge " + name); bool ok = _network.deleteNetDev(name, &why); // a device without its .netdev (left over): just the device bool ok = _network.findNetDev(name) ? _network.deleteNetDev(name, &why) : _network.deleteUnconfiguredLink(name, &why); if (!ok && !_network.findNetDev(name) && why == "no bond or bridge " + name) return Message::error(call, err::UnknownInterface, why); for (auto &i : _network.allInterfaces()) emitInterfaceState(i); return ok ? Message::reply(call) : Message::error(call, err::Failed, why); } Loading Loading
src/network.cpp +31 −2 Changes for src/network.cpp: 31 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -972,6 +972,7 @@ bool NetworkManager::deleteNetDev(const std::string &ifname, std::string *err) { unconfigureInterface(ifname); deleteLink(ifname); // its members are released with it } _createdLinks.erase(ifname); _stopped.erase(ifname); reloadConfigs(); // the member that got the addresses back has them at once, not only Loading @@ -989,6 +990,17 @@ bool NetworkManager::deleteNetDev(const std::string &ifname, std::string *err) { // kind or bond mode / STP setting (a bond's mode can't change while it has // members; its members are added again by the member configurations). void NetworkManager::applyNetDevs() { // devices syslite created whose .netdev is gone (e.g. an aborted // change put the files back): they go too for (auto it = _createdLinks.begin(); it != _createdLinks.end();) { if (findNetDev(*it)) { ++it; continue; } if (interfaceExists(*it)) { std::cout << "[syslite/net] " << *it << " has no configuration any more, deleting it" << std::endl; unconfigureInterface(*it); deleteLink(*it); } it = _createdLinks.erase(it); } for (auto &nd : _netdevs) { if (interfaceExists(nd.ifname)) { if (linkMatches(nd)) continue; Loading @@ -996,13 +1008,30 @@ void NetworkManager::applyNetDevs() { unconfigureInterface(nd.ifname); deleteLink(nd.ifname); } if (createLink(nd)) if (createLink(nd)) { _createdLinks.insert(nd.ifname); std::cout << "[syslite/net] Created " << nd.kind << " " << nd.ifname << " (" << nd.name << ".netdev)" << std::endl; else } else std::cerr << "[syslite/net] Cannot create " << nd.kind << " " << nd.ifname << std::endl; } } bool NetworkManager::deleteUnconfiguredLink(const std::string &ifname, std::string *err) { std::error_code ec; const std::string sys = "/sys/class/net/" + ifname; if (findNetDev(ifname) || !interfaceExists(ifname) || (!std::filesystem::exists(sys + "/bonding", ec) && !std::filesystem::exists(sys + "/bridge", ec))) { if (err) *err = "no bond or bridge " + ifname; return false; } std::cout << "[syslite/net] Deleting " << ifname << " (no configuration)" << std::endl; unconfigureInterface(ifname); _stopped.erase(ifname); _createdLinks.erase(ifname); if (!deleteLink(ifname)) { if (err) *err = "cannot delete " + ifname; return false; } return true; } bool NetworkManager::linkMatches(const NetDevConfig &nd) { std::error_code ec; const std::string sys = "/sys/class/net/" + nd.ifname; Loading
src/network.h +5 −0 Changes for src/network.h: 5 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -147,6 +147,10 @@ namespace syslite { bool saveNetDev(const NetDevConfig &nd, const std::vector<std::string> &members, std::string *err); bool deleteNetDev(const std::string &ifname, std::string *err); void applyNetDevs(); // a bond or bridge device without a .netdev (left over, e.g. from an // aborted change): the device only is deleted; false if ifname // isn't such a device bool deleteUnconfiguredLink(const std::string &ifname, std::string *err); // Start listening for new network devices (netlink RTNLGRP_LINK) // Returns fd to poll in the main loop (-1 on failure) Loading Loading @@ -223,6 +227,7 @@ namespace syslite { std::map<std::string, std::vector<std::string>> _dnsByIf; // DNS servers per interface std::set<std::string> _configured; // interfaces configureInterface() set up std::set<std::string> _stopped; // interfaces stopped on request std::set<std::string> _createdLinks; // bonds/bridges created by applyNetDevs bool _resolvWritten = false; // resolv.yaml is ours once written int _monitorFd = -1; }; Loading
src/syslite.cpp +5 −2 Changes for src/syslite.cpp: 5 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -509,8 +509,11 @@ namespace syslite { std::string why; if (op == m::DeleteNetDev) { if (!_network.findNetDev(name)) return Message::error(call, err::UnknownInterface, "no bond or bridge " + name); bool ok = _network.deleteNetDev(name, &why); // a device without its .netdev (left over): just the device bool ok = _network.findNetDev(name) ? _network.deleteNetDev(name, &why) : _network.deleteUnconfiguredLink(name, &why); if (!ok && !_network.findNetDev(name) && why == "no bond or bridge " + name) return Message::error(call, err::UnknownInterface, why); for (auto &i : _network.allInterfaces()) emitInterfaceState(i); return ok ? Message::reply(call) : Message::error(call, err::Failed, why); } Loading