working commit

This commit is contained in:
Олег Бородин
2026-05-21 14:15:03 +02:00
parent 3f7cfcd234
commit 5a2985f936
9 changed files with 185 additions and 16 deletions
+23
View File
@@ -16,11 +16,13 @@ extern "C" {
#include <sockhand.hpp>
#include <uxlogger.hpp>
#include <networkaux.hpp>
#include <iprouter.hpp>
#include <uxcontrol.pb.h>
void SocketHandler::Handle(int newsock, std::string laddr, std::string raddr, std::vector<std::string> routes) {
sock = newsock;
tunAddress = raddr;
auto interfaceName = std::format("uxsrv{}", sock);
auto createRes = interface.Create(interfaceName);
if (!createRes) {
@@ -213,6 +215,27 @@ void SocketHandler::RecvMessages(void) {
auto error = writeRes.error();
uxlogger.Error(std::format("Write packet error: {}", error));
}
} else if (kind == localRouteMsg) {
uxcontrol::RouteMessage routeMessage;
routeMessage.ParseFromString(rawMessage);
auto network = routeMessage.address();
auto prefix = routeMessage.prefix();
auto networkRes = nethost(network, prefix, 0);
if (!networkRes) {
uxlogger.Error(networkRes.error());
break;
}
network = networkRes.value();
uxlogger.Info(std::format("Received route {}/{} gw {}", network, prefix, tunAddress));
if (tunAddress != "") {
Router router;
auto addRouteRes = router.AddRoute(network, prefix, tunAddress, interface.Name());
if (!addRouteRes) {
uxlogger.Error(addRouteRes.error());
} else {
uxlogger.Warning(std::format("Add route {}/{}", network, prefix));
}
}
} else {
uxlogger.Warning("Received unknown kind of message");
}