@ -140,16 +140,12 @@ static void route_pkt(struct UTUN_INSTANCE* instance, struct ll_entry* entry, ui
return ;
return ;
}
}
// Determine destination node ID and connection
uint64_t dst_node_id = instance - > node_id ;
uint64_t dst_node_id = instance - > node_id ; // Default to local node
struct ETCP_CONN * conn = NULL ;
struct ETCP_CONN * conn = NULL ;
struct NODEINFO_Q * nq = route - > v_node_info ;
if ( route - > v_node_info = = NULL ) {
if ( ! nq | | nq - > node . hop_count = = 0 ) {
// Local route - send to TUN
DEBUG_TRACE ( DEBUG_CATEGORY_ROUTING , " Local route to %s " , ip_to_str ( & addr , AF_INET ) . str ) ;
DEBUG_TRACE ( DEBUG_CATEGORY_ROUTING , " Local route to %s " , ip_to_str ( & addr , AF_INET ) . str ) ;
} else {
} else {
// Learned route - use first available path from NODEINFO_Q
struct NODEINFO_Q * nq = route - > v_node_info ;
if ( nq - > paths & & nq - > paths - > head ) {
if ( nq - > paths & & nq - > paths - > head ) {
struct ll_entry * path_entry = nq - > paths - > head ;
struct ll_entry * path_entry = nq - > paths - > head ;
conn = ( struct ETCP_CONN * ) path_entry - > data ;
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 ;
return ;
}
}
dst_node_id = conn - > peer_node_id ;
dst_node_id = conn - > peer_node_id ;
if ( ! conn - > normalizer ) {
if ( ! conn - > normalizer ) {
DEBUG_WARN ( DEBUG_CATEGORY_ROUTING , " route_pkt: connection for %s has no normalizer " , ip_to_str ( & addr , AF_INET ) . str ) ;
DEBUG_WARN ( DEBUG_CATEGORY_ROUTING , " route_pkt: connection for %s has no normalizer " , ip_to_str ( & addr , AF_INET ) . str ) ;
instance - > dropped_packets + + ;
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 ) ;
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 ) {
if ( ! nq | | nq - > node . hop_count = = 0 ) {
// Local route - send to TUN (entry has [cmd=0][IP data], TUN skips cmd byte)
int put_err = queue_data_put ( instance - > tun - > input_queue , entry ) ;
int put_err = queue_data_put ( instance - > tun - > input_queue , entry ) ;
if ( put_err ! = 0 ) {
if ( put_err ! = 0 ) {
DEBUG_WARN ( DEBUG_CATEGORY_ROUTING , " route_pkt: failed to put to TUN: dst=%s err=%d " ,
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 ) ;
queue_dgram_free ( entry ) ;
return ;
return ;
}
}
// Entry sent to TUN, don't free here
instance - > routed_packets + + ;
instance - > routed_packets + + ;
DEBUG_TRACE ( DEBUG_CATEGORY_ROUTING , " route_pkt: sent %zu bytes to TUN " , ip_len ) ;
DEBUG_TRACE ( DEBUG_CATEGORY_ROUTING , " route_pkt: sent %zu bytes to TUN " , ip_len ) ;
return ;
return ;