gui + small fixes
This commit is contained in:
1 parent
9113428e7d
commit
cd169b106a
9 files changed
+242
-204
No files matched your search
@@ -419,6 +419,10 @@ static void client_read_callback(socket_t fd, void* arg) {
|
||||
if (received == SOCKET_ERROR) {
|
||||
int err = WSAGetLastError();
|
||||
if (err != WSAEWOULDBLOCK) {
|
||||
if (err == 10054) {
|
||||
client->connected = 0;
|
||||
return;
|
||||
}
|
||||
if (server && server->log_file) {
|
||||
fprintf(server->log_file, "%llu: [ERROR] Client recv error: %d\n",
|
||||
(unsigned long long)get_timestamp_ms(), err);
|
||||
|
||||
+64
-18
@@ -22,6 +22,12 @@
|
||||
// Размер пакета (без заголовка ETCP)
|
||||
#define BGP_PACKET_SIZE (sizeof(struct ROUTE_BGP_PACKET))
|
||||
|
||||
static inline void format_network(uint32_t network, char* out, size_t out_size)
|
||||
{
|
||||
uint32_t addr = htonl(network);
|
||||
inet_ntop(AF_INET, &addr, out, out_size);
|
||||
}
|
||||
|
||||
// Forward declarations
|
||||
static void route_bgp_send_route(struct ROUTE_BGP* bgp, struct ETCP_CONN* conn,
|
||||
const struct ROUTE_ENTRY* route);
|
||||
@@ -64,11 +70,20 @@ static void route_bgp_receive_cbk(struct ETCP_CONN* from_conn, struct ll_entry*
|
||||
return;
|
||||
}
|
||||
|
||||
DEBUG_INFO(DEBUG_CATEGORY_BGP, "Received BGP packet: subcmd=%d, network=%08x/%d, node_id=%016llx",
|
||||
pkt->subcmd, ntohl(pkt->network), pkt->prefix_length & 0x3F, (unsigned long long)pkt->node_id);
|
||||
char network_str[INET_ADDRSTRLEN];
|
||||
format_network(ntohl(pkt->network), network_str, sizeof(network_str));
|
||||
|
||||
DEBUG_INFO(DEBUG_CATEGORY_BGP, "Received BGP packet: subcmd=%d, network=%s/%d, node_id=%016llx",
|
||||
pkt->subcmd, network_str, pkt->prefix_length & 0x3F, (unsigned long long)pkt->node_id);
|
||||
|
||||
switch (pkt->subcmd) {
|
||||
case ROUTE_SUBCMD_ENTRY: {
|
||||
// Игнорируем маршруты от себя
|
||||
if (pkt->node_id == instance->node_id) {
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_BGP, "Ignoring own route: %s/%d", network_str, pkt->prefix_length & 0x3F);
|
||||
break;
|
||||
}
|
||||
|
||||
// Создаем запись маршрута
|
||||
struct ROUTE_ENTRY route;
|
||||
memset(&route, 0, sizeof(route));
|
||||
@@ -97,32 +112,44 @@ static void route_bgp_receive_cbk(struct ETCP_CONN* from_conn, struct ll_entry*
|
||||
}
|
||||
|
||||
// Вставляем в таблицу
|
||||
char network_str[INET_ADDRSTRLEN];
|
||||
format_network(route.network, network_str, sizeof(network_str));
|
||||
|
||||
if (route_table_insert(instance->rt, &route)) {
|
||||
DEBUG_INFO(DEBUG_CATEGORY_BGP, "Added learned route: %08x/%d via node %016llx (hops=%d)",
|
||||
route.network, route.prefix_length,
|
||||
DEBUG_INFO(DEBUG_CATEGORY_BGP, "Added learned route: %s/%d via node %016llx (hops=%d)",
|
||||
network_str, route.prefix_length,
|
||||
(unsigned long long)route.destination_node_id,
|
||||
route.metrics.hop_count);
|
||||
} else {
|
||||
DEBUG_WARN(DEBUG_CATEGORY_BGP, "Failed to insert route: %08x/%d",
|
||||
route.network, route.prefix_length);
|
||||
DEBUG_WARN(DEBUG_CATEGORY_BGP, "Failed to insert route: %s/%d",
|
||||
network_str, route.prefix_length);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case ROUTE_SUBCMD_WITHDRAW: {
|
||||
// Игнорируем withdraw от себя
|
||||
if (pkt->node_id == instance->node_id) {
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_BGP, "Ignoring own withdraw: %s/%d", network_str, pkt->prefix_length & 0x3F);
|
||||
break;
|
||||
}
|
||||
|
||||
// Удаление маршрута (withdrawal)
|
||||
uint32_t network = ntohl(pkt->network);
|
||||
uint8_t prefix_length = pkt->prefix_length & 0x3F;
|
||||
|
||||
DEBUG_INFO(DEBUG_CATEGORY_BGP, "Processing route withdrawal: %08x/%d from conn %p",
|
||||
network, prefix_length, (void*)from_conn);
|
||||
char network_str[INET_ADDRSTRLEN];
|
||||
format_network(network, network_str, sizeof(network_str));
|
||||
|
||||
DEBUG_INFO(DEBUG_CATEGORY_BGP, "Processing route withdrawal: %s/%d from conn %p",
|
||||
network_str, prefix_length, (void*)from_conn);
|
||||
|
||||
if (route_table_delete_entry(instance->rt, network, prefix_length, from_conn)) {
|
||||
DEBUG_INFO(DEBUG_CATEGORY_BGP, "Route withdrawn successfully: %08x/%d",
|
||||
network, prefix_length);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_BGP, "Route withdrawn successfully: %s/%d",
|
||||
network_str, prefix_length);
|
||||
} else {
|
||||
DEBUG_WARN(DEBUG_CATEGORY_BGP, "Route to withdraw not found: %08x/%d",
|
||||
network, prefix_length);
|
||||
DEBUG_WARN(DEBUG_CATEGORY_BGP, "Route to withdraw not found: %s/%d",
|
||||
network_str, prefix_length);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -154,6 +181,11 @@ static void route_bgp_send_withdraw(struct ROUTE_BGP* bgp, struct ETCP_CONN* con
|
||||
return;
|
||||
}
|
||||
|
||||
// Не отправляем withdraw автору маршрута
|
||||
if (route->destination_node_id == conn->peer_node_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Создаем ETCP пакет
|
||||
struct ll_entry* entry = ll_alloc_lldgram(sizeof(struct ROUTE_BGP_PACKET));
|
||||
if (!entry) {
|
||||
@@ -175,8 +207,11 @@ static void route_bgp_send_withdraw(struct ROUTE_BGP* bgp, struct ETCP_CONN* con
|
||||
|
||||
entry->len = sizeof(struct ROUTE_BGP_PACKET);
|
||||
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_BGP, "Sending withdraw: %08x/%d to conn %p",
|
||||
route->network, route->prefix_length, (void*)conn);
|
||||
char network_str[INET_ADDRSTRLEN];
|
||||
format_network(route->network, network_str, sizeof(network_str));
|
||||
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_BGP, "Sending withdraw: %s/%d to conn %p",
|
||||
network_str, route->prefix_length, (void*)conn);
|
||||
|
||||
// Отправляем через ETCP
|
||||
if (etcp_send(conn, entry) != 0) {
|
||||
@@ -238,8 +273,11 @@ static void route_bgp_on_route_change(struct ROUTE_TABLE* table,
|
||||
// Не рассылаем маршруты через которые мы их получили (чтобы избежать петель)
|
||||
// Это делается в цикле ниже
|
||||
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_BGP, "Route change: action=%d, network=%08x/%d, type=%d",
|
||||
action, entry->network, entry->prefix_length, entry->type);
|
||||
char network_str[INET_ADDRSTRLEN];
|
||||
format_network(entry->network, network_str, sizeof(network_str));
|
||||
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_BGP, "Route change: action=%d, network=%s/%d, type=%d",
|
||||
action, network_str, entry->prefix_length, entry->type);
|
||||
|
||||
// Перебираем все соединения в senders_list
|
||||
struct ll_entry* item_entry = bgp->senders_list->head;
|
||||
@@ -272,6 +310,11 @@ static void route_bgp_send_route(struct ROUTE_BGP* bgp, struct ETCP_CONN* conn,
|
||||
return;
|
||||
}
|
||||
|
||||
// Не отправляем маршрут автору этого маршрута
|
||||
if (route->destination_node_id == conn->peer_node_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Пропускаем неактивные маршруты
|
||||
if (!(route->flags & ROUTE_FLAG_ACTIVE)) {
|
||||
return;
|
||||
@@ -313,8 +356,11 @@ static void route_bgp_send_route(struct ROUTE_BGP* bgp, struct ETCP_CONN* conn,
|
||||
|
||||
entry->len = sizeof(struct ROUTE_BGP_PACKET);
|
||||
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_BGP, "Sending route: %08x/%d to conn %p",
|
||||
route->network, route->prefix_length & 0x3F, (void*)conn);
|
||||
char network_str[INET_ADDRSTRLEN];
|
||||
format_network(route->network, network_str, sizeof(network_str));
|
||||
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_BGP, "Sending route: %s/%d to conn %p",
|
||||
network_str, route->prefix_length & 0x3F, (void*)conn);
|
||||
|
||||
// Отправляем через ETCP
|
||||
if (etcp_send(conn, entry) != 0) {
|
||||
|
||||
Reference in new issue
Block a user