This commit is contained in:
jeka committed 2026-02-22 23:28:11 +03:00
1 parent 17e1a193c5
commit b27ea97055
6 files changed
+136

No files matched your search

+4
View File
@@ -99,6 +99,10 @@ static int parse_key_value(const char *line, char *key, size_t key_len, char *va
size_t val_len = strlen(val_start);
if (val_len >= value_len) return -1;
strcpy(value, val_start);
char *comment = strchr(value, '#');
if (comment) *comment = '\0';
trim(value);
return 0;
+18
View File
@@ -491,6 +491,7 @@ struct ETCP_SOCKET* etcp_socket_add(struct UTUN_INSTANCE* instance, struct socka
e_sock->errorcode = 0;
e_sock->pkt_format_errors = 0;
e_sock->type = type;
DEBUG_INFO(DEBUG_CATEGORY_BGP, "Add Socket type=%d", type);
// Add to instance's socket list
e_sock->next = instance->etcp_sockets;
@@ -1136,7 +1137,24 @@ int init_connections(struct UTUN_INSTANCE* instance) {
struct CFG_SERVER* server = config->servers;
while (server) {
// Create socket for this server
// Auto-detect local IP for public servers with 0.0.0.0
uint32_t default_ip = 0;
if (server->type == CFG_SERVER_TYPE_PUBLIC) {
struct sockaddr_in* sin = (struct sockaddr_in*)&server->ip;
if (sin->sin_addr.s_addr == 0) {
default_ip = get_default_route_ip();
if (default_ip == 0) {
DEBUG_WARN(DEBUG_CATEGORY_ETCP, "Failed to detect default route IP for server %s", server->name);
}
}
}
struct ETCP_SOCKET* e_sock = etcp_socket_add(instance, &server->ip, server->netif_index, server->so_mark, server->type);
if (e_sock && default_ip != 0) {
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "Server %s type %d ip=%08x", server->name, server->type, default_ip);
e_sock->local_defaultroute_ip = default_ip;
}
if (!e_sock) {
DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "Failed to create socket for server %s", server->name);
server = server->next;
+1
View File
@@ -44,6 +44,7 @@ struct ETCP_SOCKET {
void* socket_id; // Socket ID from uasync_add_socket
uint8_t type; // CFG_SERVER_TYPE_PUBLIC/NAT/PRIVATE
uint32_t local_defaultroute_ip; // auto-detected IPv4 for public servers (network byte order)
};
// ETCP Link - одно динамическое соединение (один путь)
+6
View File
@@ -383,10 +383,13 @@ static void route_bgp_send_route(struct ROUTE_BGP* bgp, struct ETCP_CONN* conn,
// Первый проход - PUBLIC
while (link) {
DEBUG_INFO(DEBUG_CATEGORY_BGP, "Sending routine: scanning conn type=%d init=%d", link->conn->type, link->initialized);
if (link->conn && link->conn->type == CFG_SERVER_TYPE_PUBLIC && link->initialized) {
struct sockaddr_in* sin = (struct sockaddr_in*)&link->conn->local_addr;
uint32_t ip = *(uint32_t*)&sin->sin_addr;
uint16_t port = sin->sin_port;
DEBUG_INFO(DEBUG_CATEGORY_BGP, "Sending routine [public]");
route_bgp_send_route_single(bgp, conn, route, ip, port);
sent_any = 1;
}
@@ -399,6 +402,7 @@ static void route_bgp_send_route(struct ROUTE_BGP* bgp, struct ETCP_CONN* conn,
if (link->conn && link->conn->type == CFG_SERVER_TYPE_NAT && link->nat_ip && link->initialized) {
uint32_t ip = link->nat_ip;
uint16_t port = link->nat_port;
DEBUG_INFO(DEBUG_CATEGORY_BGP, "Sending routine [nat]");
route_bgp_send_route_single(bgp, conn, route, ip, port);
sent_any = 1;
}
@@ -407,10 +411,12 @@ static void route_bgp_send_route(struct ROUTE_BGP* bgp, struct ETCP_CONN* conn,
// Если нет PUBLIC и NAT - отправляем без endpoint (0.0.0.0:0)
if (!sent_any) {
DEBUG_INFO(DEBUG_CATEGORY_BGP, "Sending routine [any]");
route_bgp_send_route_single(bgp, conn, route, 0, 0);
}
} else {
// Для LEARNED маршрутов - используем endpoint из route
DEBUG_INFO(DEBUG_CATEGORY_BGP, "Sending routine [learned]");
route_bgp_send_route_single(bgp, conn, route,
htonl(route->endpoint_ip),
htons(route->endpoint_port));