Routing: add local routes to table via hop_count==0 detection
This commit is contained in:
1 parent
b72d89da2d
commit
ad87ea60de
3 files changed
+9
-24
No files matched your search
+1
-2
@@ -277,8 +277,7 @@ void route_table_print(const struct ROUTE_TABLE *table) {
|
||||
const struct ROUTE_ENTRY *entry = &table->entries[i];
|
||||
DEBUG_INFO(DEBUG_CATEGORY_ROUTING, " %zu: %s/%d",
|
||||
i + 1, ip_to_string(entry->network).a, entry->prefix_length);
|
||||
|
||||
if (entry->v_node_info) {
|
||||
if (entry->v_node_info && entry->v_node_info->node.hop_count != 0) {
|
||||
DEBUG_INFO(DEBUG_CATEGORY_ROUTING, " v_node_info=%p", (void*)entry->v_node_info);
|
||||
} else {
|
||||
DEBUG_INFO(DEBUG_CATEGORY_ROUTING, " LOCAL");
|
||||
|
||||
+4
-11
@@ -140,16 +140,12 @@ static void route_pkt(struct UTUN_INSTANCE* instance, struct ll_entry* entry, ui
|
||||
return;
|
||||
}
|
||||
|
||||
// Determine destination node ID and connection
|
||||
uint64_t dst_node_id = instance->node_id; // Default to local node
|
||||
uint64_t dst_node_id = instance->node_id;
|
||||
struct ETCP_CONN* conn = NULL;
|
||||
|
||||
if (route->v_node_info == NULL) {
|
||||
// Local route - send to TUN
|
||||
struct NODEINFO_Q* nq = route->v_node_info;
|
||||
if (!nq || nq->node.hop_count == 0) {
|
||||
DEBUG_TRACE(DEBUG_CATEGORY_ROUTING, "Local route to %s", ip_to_str(&addr, AF_INET).str);
|
||||
} else {
|
||||
// Learned route - use first available path from NODEINFO_Q
|
||||
struct NODEINFO_Q* nq = route->v_node_info;
|
||||
if (nq->paths && nq->paths->head) {
|
||||
struct ll_entry* path_entry = nq->paths->head;
|
||||
conn = (struct ETCP_CONN*)path_entry->data;
|
||||
@@ -163,7 +159,6 @@ static void route_pkt(struct UTUN_INSTANCE* instance, struct ll_entry* entry, ui
|
||||
return;
|
||||
}
|
||||
dst_node_id = conn->peer_node_id;
|
||||
|
||||
if (!conn->normalizer) {
|
||||
DEBUG_WARN(DEBUG_CATEGORY_ROUTING, "route_pkt: connection for %s has no normalizer", ip_to_str(&addr, AF_INET).str);
|
||||
instance->dropped_packets++;
|
||||
@@ -179,8 +174,7 @@ static void route_pkt(struct UTUN_INSTANCE* instance, struct ll_entry* entry, ui
|
||||
}
|
||||
else DEBUG_INFO(DEBUG_CATEGORY_TRAFFIC, "NODE %016llx -> NODE %016llx", (unsigned long long)src_node_id, (unsigned long long)dst_node_id);
|
||||
|
||||
if (route->v_node_info == NULL) {
|
||||
// Local route - send to TUN (entry has [cmd=0][IP data], TUN skips cmd byte)
|
||||
if (!nq || nq->node.hop_count == 0) {
|
||||
int put_err = queue_data_put(instance->tun->input_queue, entry);
|
||||
if (put_err != 0) {
|
||||
DEBUG_WARN(DEBUG_CATEGORY_ROUTING, "route_pkt: failed to put to TUN: dst=%s err=%d",
|
||||
@@ -190,7 +184,6 @@ static void route_pkt(struct UTUN_INSTANCE* instance, struct ll_entry* entry, ui
|
||||
queue_dgram_free(entry);
|
||||
return;
|
||||
}
|
||||
// Entry sent to TUN, don't free here
|
||||
instance->routed_packets++;
|
||||
DEBUG_TRACE(DEBUG_CATEGORY_ROUTING, "route_pkt: sent %zu bytes to TUN", ip_len);
|
||||
return;
|
||||
|
||||
+4
-11
@@ -74,10 +74,6 @@ static int instance_init_common(struct UTUN_INSTANCE* instance, struct UASYNC* u
|
||||
return -1;
|
||||
}
|
||||
DEBUG_INFO(DEBUG_CATEGORY_ROUTING, "Routing module created");
|
||||
|
||||
if(instance->bgp&&instance->bgp->local_node){if(route_insert(instance->rt,instance->bgp->local_node)){DEBUG_INFO(DEBUG_CATEGORY_ROUTING,"Added local routes from local_node");}else{DEBUG_WARN(DEBUG_CATEGORY_ROUTING,"Failed to add local routes");}}
|
||||
|
||||
// Initialize TUN device if enabled
|
||||
if (g_tun_init_enabled) {
|
||||
instance->tun = tun_init(ua, config);
|
||||
if (!instance->tun) {
|
||||
@@ -85,8 +81,6 @@ static int instance_init_common(struct UTUN_INSTANCE* instance, struct UASYNC* u
|
||||
return -1;
|
||||
}
|
||||
DEBUG_INFO(DEBUG_CATEGORY_TUN, "TUN interface initialized: %s", instance->tun->ifname);
|
||||
|
||||
// Add system routes for route_subnets
|
||||
if (config->route_subnets) {
|
||||
int added = tun_route_add_all(instance->tun->ifindex, instance->tun->ifname, config->route_subnets);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_TUN, "Added %d system routes for TUN interface", added);
|
||||
@@ -96,20 +90,19 @@ static int instance_init_common(struct UTUN_INSTANCE* instance, struct UASYNC* u
|
||||
DEBUG_INFO(DEBUG_CATEGORY_TUN, "TUN initialization disabled - skipping TUN device setup");
|
||||
instance->tun = NULL;
|
||||
}
|
||||
|
||||
// Initialize sockets first (needed for BGP nodeinfo)
|
||||
if (init_sockets(instance) < 0) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "Failed to initialize sockets");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Initialize BGP module for route exchange
|
||||
instance->bgp = route_bgp_init(instance);
|
||||
if (!instance->bgp) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_BGP, "Failed to initialize BGP module");
|
||||
// Non-fatal: BGP is optional for basic operation
|
||||
} else {
|
||||
DEBUG_INFO(DEBUG_CATEGORY_BGP, "BGP module initialized");
|
||||
if (instance->rt && instance->bgp->local_node) {
|
||||
route_bgp_update_my_nodeinfo(instance,instance->bgp);
|
||||
if (route_insert(instance->rt,instance->bgp->local_node)) DEBUG_INFO(DEBUG_CATEGORY_ROUTING,"Added local routes"); else DEBUG_WARN(DEBUG_CATEGORY_ROUTING,"Failed to add local routes");
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize firewall
|
||||
|
||||
Reference in new issue
Block a user