This commit is contained in:
jeka committed 2026-03-12 04:36:45 +03:00
1 parent aa5171bcd1
commit e8b6153297
6 files changed
+42 -16

No files matched your search

+2 -3
View File
@@ -848,8 +848,7 @@ static void etcp_connections_read_callback_socket(socket_t sock, void* arg) {
uint8_t link_id;
uint8_t pubkey[SC_PUBKEY_SIZE];
} *ack_hdr=(void*)&pkt->data[0];
uint64_t peer_id;
memcpy(&peer_id, &ack_hdr->id[0], 8);
uint64_t peer_id = be64toh(*(uint64_t*)ack_hdr->id);
if (ack_hdr->code!=ETCP_INIT_REQUEST && ack_hdr->code!=ETCP_INIT_REQUEST_NOINIT) {
DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "etcp_connections_read_callback: not an init packet, code=%02x", ack_hdr->code);
errorcode=4;
@@ -938,7 +937,7 @@ static void etcp_connections_read_callback_socket(socket_t sock, void* arg) {
} else {
ack_repl_hdr->code = ETCP_INIT_RESPONSE_NOINIT; // 0x05 - without reset
}
memcpy(ack_repl_hdr->id, &e_sock->instance->node_id, 8);
*(uint64_t*)ack_repl_hdr->id = htobe64(e_sock->instance->node_id);
ack_repl_hdr->mtu[0]=link->mtu_local>>8;
ack_repl_hdr->mtu[1]=link->mtu_local;
+21 -4
View File
@@ -156,19 +156,36 @@ static void route_bgp_broadcast_withdraw(struct ROUTE_BGP* bgp, uint64_t node_id
static void route_bgp_on_route_change(struct ROUTE_TABLE* table,
struct ROUTE_ENTRY* entry,
int action, void* arg) {
int action,
uint64_t changed_from,
void* arg) {
struct ROUTE_BGP* bgp = (struct ROUTE_BGP*)arg;
if (!bgp || !entry) return;
// changed_from - это peer_node_id от кого пришёл маршрут (0 для локальных)
// находим conn по peer_node_id для использования как exclude
struct ETCP_CONN* exclude_conn = NULL;
if (changed_from != 0) {
struct ll_entry* e = bgp->senders_list->head;
while (e) {
struct ROUTE_BGP_CONN_ITEM* item = (struct ROUTE_BGP_CONN_ITEM*)e->data;
if (item->conn->peer_node_id == changed_from) {
exclude_conn = item->conn;
break;
}
e = e->next;
}
}
if (action == 0) { // insert
route_bgp_broadcast_route(bgp, entry, NULL, ROUTE_SUBCMD_ENTRY);
route_bgp_broadcast_route(bgp, entry, exclude_conn, ROUTE_SUBCMD_ENTRY);
}
else if (action == 1) { // update / reroute / hop_list changed
route_bgp_broadcast_route(bgp, entry, NULL, ROUTE_SUBCMD_ENTRY_REROUTE);
route_bgp_broadcast_route(bgp, entry, exclude_conn, ROUTE_SUBCMD_ENTRY_REROUTE);
}
else if (action == 2) { // withdraw
uint64_t node_id = entry->conn_list ? entry->conn_list->node_id : 0;
route_bgp_broadcast_withdraw(bgp, node_id, NULL);
route_bgp_broadcast_withdraw(bgp, node_id, exclude_conn);
}
}
+15 -7
View File
@@ -379,6 +379,14 @@ bool route_insert(struct ROUTE_TABLE *table,
}
}
uint64_t peer_node_id=0;
if (conn) {
peer_node_id=conn->peer_node_id;
DEBUG_INFO(DEBUG_CATEGORY_ROUTING, "peer: %s %016llx", conn->log_name, (unsigned long long)peer_node_id);
}
else DEBUG_INFO(DEBUG_CATEGORY_ROUTING, "no peer");
// === 1. Точный матч префикса ===
struct ROUTE_ENTRY *existing = find_exact(table, entry->network, entry->prefix_length);
@@ -397,7 +405,7 @@ bool route_insert(struct ROUTE_TABLE *table,
if (new_local) {
existing->last_update = get_time_tb();
if (table->change_callback)
table->change_callback(table, existing, 1, table->change_callback_arg);
table->change_callback(table, existing, 1, peer_node_id, table->change_callback_arg);
DEBUG_TRACE(DEBUG_CATEGORY_ROUTING, "route_insert: UPDATED local route %s/%d", ip_to_string(entry->network).a, entry->prefix_length);
return true;
}
@@ -415,7 +423,7 @@ bool route_insert(struct ROUTE_TABLE *table,
existing->last_update = get_time_tb();
if (table->change_callback)
table->change_callback(table, existing, 1, table->change_callback_arg);
table->change_callback(table, existing, 1, peer_node_id, table->change_callback_arg);
DEBUG_INFO(DEBUG_CATEGORY_ROUTING, "route_insert: UPDATED learned route %s/%d node_id=%016llx",
ip_to_string(entry->network).a, entry->prefix_length, (unsigned long long)node_id);
@@ -486,7 +494,7 @@ bool route_insert(struct ROUTE_TABLE *table,
// === 7. Callback ===
if (table->change_callback) {
table->change_callback(table, &table->entries[pos], 0, table->change_callback_arg);
table->change_callback(table, &table->entries[pos], 0, peer_node_id, table->change_callback_arg);
}
// === 8. Отладочное сообщение ===
@@ -545,7 +553,7 @@ void route_remove_conn(struct ROUTE_TABLE *table, struct ETCP_CONN *conn) {
struct ROUTE_ENTRY *e = &table->entries[i];
if (e->conn_list && e->conn_list->conninfo_count == 0) {
if (table->change_callback)
table->change_callback(table, e, 2, table->change_callback_arg);
table->change_callback(table, e, 2, 0, table->change_callback_arg);
struct NODE_CONNS_INFO *info = e->conn_list;
e->conn_list = NULL;
@@ -566,7 +574,7 @@ void route_remove_conn(struct ROUTE_TABLE *table, struct ETCP_CONN *conn) {
if (affected[k] == e->conn_list && needs_reroute[k]) {
e->last_update = get_time_tb();
if (table->change_callback)
table->change_callback(table, e, 1, table->change_callback_arg);
table->change_callback(table, e, 1, 0, table->change_callback_arg);
break;
}
}
@@ -613,7 +621,7 @@ bool route_remove_path(struct ROUTE_TABLE *table,
if (e->conn_list == info) {
e->last_update = get_time_tb();
if (table->change_callback)
table->change_callback(table, e, 1, table->change_callback_arg);
table->change_callback(table, e, 1, 0, table->change_callback_arg);
}
}
DEBUG_INFO(DEBUG_CATEGORY_ROUTING, "route_remove_path: REROUTE node_id=%016llx", (unsigned long long)node_id);
@@ -648,7 +656,7 @@ void route_delete(struct ROUTE_TABLE *table, uint64_t node_id) {
entry->conn_list = NULL;
if (table->change_callback) {
table->change_callback(table, entry, 2, table->change_callback_arg);
table->change_callback(table, entry, 2, 0, table->change_callback_arg);
}
if (i < table->count - 1) {
+1
View File
@@ -50,6 +50,7 @@ struct NODE_CONNS_INFO {// Один NODE_CONNS_INFO на один node_id. не
typedef void (*route_change_callback_fn)(struct ROUTE_TABLE* table,
struct ROUTE_ENTRY* entry,
int action,
uint64_t changed_from, /**< peer_node_id от кого пришло изменение, 0 если локальное */
void* arg);
+1 -1
View File
@@ -73,7 +73,7 @@ static int instance_init_common(struct UTUN_INSTANCE* instance, struct UASYNC* u
entry.network = ntohl(subnet->ip.addr.v4.s_addr); // Convert network byte order to host
entry.prefix_length = subnet->netmask;
if (route_insert(instance->rt, &entry, NULL, 0, 0, NULL, 0)) {
if (route_insert(instance->rt, &entry, NULL, 0, instance->node_id, NULL, 0)) {
struct in_addr addr;
addr.s_addr = htonl(entry.network);
DEBUG_INFO(DEBUG_CATEGORY_ROUTING, "Added local route: %s/%d",