Loading include/sysbus/client.h +2 −0 Changes for include/sysbus/client.h: 2 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -181,6 +181,8 @@ struct NetDevInfo { std::string config; // file name without ".netdev" std::string configPath; bool exists = false; // the device is there std::string configAddress; // its own .network's Address= std::string applyError; // why it couldn't be created/configured std::vector<std::string> members; // configured members }; Loading src/network.cpp +22 −1 Changes for src/network.cpp: 22 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -677,6 +677,11 @@ bool NetworkManager::reloadInterface(const std::string &ifname, std::string *err if (!ifname.empty() && !interfaceExists(ifname) && !findNetDev(ifname)) { if (err) *err = "no interface " + ifname; return false; } reloadConfigs(); applyNetDevs(); // a .netdev's device that couldn't be made: nothing to configure if (!ifname.empty() && !interfaceExists(ifname)) { if (err) *err = netDevError(ifname).empty() ? "no interface " + ifname : netDevError(ifname); return false; } auto cfgOf = [this](const std::string &i) { return configFor(i); }; auto isNetDev = [this](const std::string &i) { return findNetDev(i) != nullptr; }; std::vector<std::string> targets = membersFirst(ifname.empty() ? enumInterfaces() : std::vector<std::string>{ifname}, cfgOf, isNetDev); Loading @@ -697,6 +702,11 @@ bool NetworkManager::reloadInterface(const std::string &ifname, std::string *err configureInterface(i, *cfg); } updateResolv(); // e.g. WireGuard keys or peers the kernel refused if (!ifname.empty() && !netDevError(ifname).empty()) { if (err) *err = netDevError(ifname); return false; } return true; } Loading Loading @@ -1107,6 +1117,7 @@ bool NetworkManager::deleteNetDev(const std::string &ifname, std::string *err) { deleteLink(ifname); // its members are released with it } _createdLinks.erase(ifname); _netDevErrors.erase(ifname); _stopped.erase(ifname); reloadConfigs(); // the member that got the addresses back has them at once, not only Loading Loading @@ -1147,9 +1158,13 @@ void NetworkManager::applyNetDevs() { deleteLink(nd.ifname); } } _netDevErrors.erase(nd.ifname); if (!there) { if (!createLink(nd)) { std::cerr << "[syslite/net] Cannot create " << nd.kind << " " << nd.ifname << std::endl; std::string why = "cannot create " + nd.kind + " " + nd.ifname; if (nd.kind == "wireguard") why += " (does the kernel have WireGuard?)"; std::cerr << "[syslite/net] " << why << std::endl; _netDevErrors[nd.ifname] = why; continue; } _createdLinks.insert(nd.ifname); Loading @@ -1161,6 +1176,7 @@ void NetworkManager::applyNetDevs() { std::string why; if (!configureWireGuard(nd, &why)) { std::cerr << "[syslite/net] " << why << std::endl; _netDevErrors[nd.ifname] = why; continue; } // without a .network nothing else brings it up (with one, Loading @@ -1172,6 +1188,11 @@ void NetworkManager::applyNetDevs() { } } std::string NetworkManager::netDevError(const std::string &ifname) const { auto it = _netDevErrors.find(ifname); return it == _netDevErrors.end() ? "" : it->second; } bool NetworkManager::configureWireGuard(const NetDevConfig &nd, std::string *err) { if (nd.wgPrivateKey.empty()) { if (err) *err = nd.ifname + ": no private key" + Loading src/network.h +3 −0 Changes for src/network.h: 3 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -163,6 +163,8 @@ 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(); // why applyNetDevs() couldn't create or configure ifname ("": it could) std::string netDevError(const std::string &ifname) const; // a bond, bridge or WireGuard 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 Loading Loading @@ -256,6 +258,7 @@ namespace syslite { 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 std::map<std::string, std::string> _netDevErrors; // applyNetDevs() failures by ifname bool _resolvWritten = false; // resolv.yaml is ours once written int _monitorFd = -1; }; Loading src/sysbus/client.cpp +2 −0 Changes for src/sysbus/client.cpp: 2 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -93,6 +93,8 @@ NetDevInfo netDevFromFields(const std::vector<std::pair<std::string, std::string else if (k == "config") n.config = v; else if (k == "config_path") n.configPath = v; else if (k == "exists") n.exists = v == "yes"; else if (k == "config_address") n.configAddress = v; else if (k == "apply_error") n.applyError = v; else if (k == "member") n.members.push_back(v); else if (k == "public_key") n.publicKey = v; else if (k == "listen_port") n.listenPort = std::atoi(v.c_str()); Loading src/syslite.cpp +8 −0 Changes for src/syslite.cpp: 8 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -519,6 +519,14 @@ namespace syslite { r.add("config", nd.name); r.add("config_path", nd.filePath); r.add("exists", _network.interfaceExists(nd.ifname) ? "yes" : "no"); // its own addresses (its .network), also while the device isn't there for (auto &c : _network.configs()) if (c.matchName == nd.ifname && c.bond.empty() && c.bridge.empty()) { r.add("config_address", c.address); break; } const std::string error = _network.netDevError(nd.ifname); if (!error.empty()) r.add("apply_error", error); for (auto &mem : _network.membersOf(nd.ifname)) r.add("member", mem); } return r; Loading Loading
include/sysbus/client.h +2 −0 Changes for include/sysbus/client.h: 2 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -181,6 +181,8 @@ struct NetDevInfo { std::string config; // file name without ".netdev" std::string configPath; bool exists = false; // the device is there std::string configAddress; // its own .network's Address= std::string applyError; // why it couldn't be created/configured std::vector<std::string> members; // configured members }; Loading
src/network.cpp +22 −1 Changes for src/network.cpp: 22 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -677,6 +677,11 @@ bool NetworkManager::reloadInterface(const std::string &ifname, std::string *err if (!ifname.empty() && !interfaceExists(ifname) && !findNetDev(ifname)) { if (err) *err = "no interface " + ifname; return false; } reloadConfigs(); applyNetDevs(); // a .netdev's device that couldn't be made: nothing to configure if (!ifname.empty() && !interfaceExists(ifname)) { if (err) *err = netDevError(ifname).empty() ? "no interface " + ifname : netDevError(ifname); return false; } auto cfgOf = [this](const std::string &i) { return configFor(i); }; auto isNetDev = [this](const std::string &i) { return findNetDev(i) != nullptr; }; std::vector<std::string> targets = membersFirst(ifname.empty() ? enumInterfaces() : std::vector<std::string>{ifname}, cfgOf, isNetDev); Loading @@ -697,6 +702,11 @@ bool NetworkManager::reloadInterface(const std::string &ifname, std::string *err configureInterface(i, *cfg); } updateResolv(); // e.g. WireGuard keys or peers the kernel refused if (!ifname.empty() && !netDevError(ifname).empty()) { if (err) *err = netDevError(ifname); return false; } return true; } Loading Loading @@ -1107,6 +1117,7 @@ bool NetworkManager::deleteNetDev(const std::string &ifname, std::string *err) { deleteLink(ifname); // its members are released with it } _createdLinks.erase(ifname); _netDevErrors.erase(ifname); _stopped.erase(ifname); reloadConfigs(); // the member that got the addresses back has them at once, not only Loading Loading @@ -1147,9 +1158,13 @@ void NetworkManager::applyNetDevs() { deleteLink(nd.ifname); } } _netDevErrors.erase(nd.ifname); if (!there) { if (!createLink(nd)) { std::cerr << "[syslite/net] Cannot create " << nd.kind << " " << nd.ifname << std::endl; std::string why = "cannot create " + nd.kind + " " + nd.ifname; if (nd.kind == "wireguard") why += " (does the kernel have WireGuard?)"; std::cerr << "[syslite/net] " << why << std::endl; _netDevErrors[nd.ifname] = why; continue; } _createdLinks.insert(nd.ifname); Loading @@ -1161,6 +1176,7 @@ void NetworkManager::applyNetDevs() { std::string why; if (!configureWireGuard(nd, &why)) { std::cerr << "[syslite/net] " << why << std::endl; _netDevErrors[nd.ifname] = why; continue; } // without a .network nothing else brings it up (with one, Loading @@ -1172,6 +1188,11 @@ void NetworkManager::applyNetDevs() { } } std::string NetworkManager::netDevError(const std::string &ifname) const { auto it = _netDevErrors.find(ifname); return it == _netDevErrors.end() ? "" : it->second; } bool NetworkManager::configureWireGuard(const NetDevConfig &nd, std::string *err) { if (nd.wgPrivateKey.empty()) { if (err) *err = nd.ifname + ": no private key" + Loading
src/network.h +3 −0 Changes for src/network.h: 3 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -163,6 +163,8 @@ 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(); // why applyNetDevs() couldn't create or configure ifname ("": it could) std::string netDevError(const std::string &ifname) const; // a bond, bridge or WireGuard 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 Loading Loading @@ -256,6 +258,7 @@ namespace syslite { 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 std::map<std::string, std::string> _netDevErrors; // applyNetDevs() failures by ifname bool _resolvWritten = false; // resolv.yaml is ours once written int _monitorFd = -1; }; Loading
src/sysbus/client.cpp +2 −0 Changes for src/sysbus/client.cpp: 2 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -93,6 +93,8 @@ NetDevInfo netDevFromFields(const std::vector<std::pair<std::string, std::string else if (k == "config") n.config = v; else if (k == "config_path") n.configPath = v; else if (k == "exists") n.exists = v == "yes"; else if (k == "config_address") n.configAddress = v; else if (k == "apply_error") n.applyError = v; else if (k == "member") n.members.push_back(v); else if (k == "public_key") n.publicKey = v; else if (k == "listen_port") n.listenPort = std::atoi(v.c_str()); Loading
src/syslite.cpp +8 −0 Changes for src/syslite.cpp: 8 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -519,6 +519,14 @@ namespace syslite { r.add("config", nd.name); r.add("config_path", nd.filePath); r.add("exists", _network.interfaceExists(nd.ifname) ? "yes" : "no"); // its own addresses (its .network), also while the device isn't there for (auto &c : _network.configs()) if (c.matchName == nd.ifname && c.bond.empty() && c.bridge.empty()) { r.add("config_address", c.address); break; } const std::string error = _network.netDevError(nd.ifname); if (!error.empty()) r.add("apply_error", error); for (auto &mem : _network.membersOf(nd.ifname)) r.add("member", mem); } return r; Loading