Files
utun2/!/routing.h
T
Evgeny 26fc933d94 Fix: Resolved double free in timeout_heap_pop() and test_etcp_simple_traffic bind conflict
- Fixed incorrect init_connections() call in test_etcp_simple_traffic.c (was calling server_instance instead of client_instance)
- Fixed double free in timeout_heap_pop() when handling deleted elements
- Enhanced NULL pointer safety in uasync_print_resources() by removing complex heap manipulation
- Added debug logging to timeout_heap_pop() for better error tracking

Test results: test_etcp_simple_traffic now passes without double free errors
2026-01-25 10:47:02 +03:00

88 lines
2.8 KiB
C
Executable File

#ifndef ROUTING_H
#define ROUTING_H
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
// Forward declarations
struct ETCP_CONNECTIONS;
// Типы маршрутов
typedef enum {
ROUTE_TYPE_STATIC = 0,
ROUTE_TYPE_DYNAMIC = 1,
ROUTE_TYPE_LOCAL = 2,
ROUTE_TYPE_LEARNED = 3
} route_type_t;
// Флаги маршрута
typedef enum {
ROUTE_FLAG_ACTIVE = (1 << 0),
ROUTE_FLAG_VALIDATED = (1 << 1),
ROUTE_FLAG_ADVERTISED = (1 << 2),
ROUTE_FLAG_LEARNED = (1 << 3)
} route_flags_t;
// Расширенные метрики маршрута
struct route_metrics {
uint32_t bandwidth_kbps;
uint16_t packet_loss_rate;
uint16_t latency_ms;
uint8_t hop_count;
uint64_t last_updated;
};
// Расширенная запись маршрута
struct route_entry {
uint32_t network;
uint8_t prefix_length;
uint32_t next_hop_ip;
struct ETCP_SOCKET* next_hop;
route_type_t type;
uint8_t flags;
struct route_metrics metrics;
uint64_t created_time;
uint64_t last_update;
uint64_t last_used;
};
// Таблица маршрутизации
struct routing_table {
struct route_entry *entries;
size_t count;
size_t capacity;
uint32_t *dynamic_subnets;
size_t dynamic_subnet_count;
uint32_t *local_subnets;
size_t local_subnet_count;
struct {
uint64_t total_routes;
uint64_t static_routes;
uint64_t dynamic_routes;
uint64_t local_routes;
uint64_t learned_routes;
uint64_t routes_added;
uint64_t routes_deleted;
uint64_t lookup_count;
uint64_t hit_count;
uint64_t routes_lookup_hits;
uint64_t routes_lookup_misses;
uint64_t validation_failures;
} stats;
};
struct routing_table *routing_table_create(void);
void routing_table_destroy(struct routing_table *table);
bool routing_table_insert(struct routing_table *table, const struct route_entry *entry);
bool routing_table_delete(struct routing_table *table, uint32_t network, uint8_t prefix_length, uint32_t source_node_id);
bool routing_table_lookup(struct routing_table *table, uint32_t dest_ip, struct route_entry *best_route);
bool routing_validate_route(struct routing_table *table, uint32_t network, uint8_t prefix_length, route_type_t route_type);
bool routing_add_dynamic_subnet(struct routing_table *table, uint32_t network, uint8_t prefix_length);
bool routing_add_local_subnet(struct routing_table *table, uint32_t network, uint8_t prefix_length);
bool routing_get_all_routes(const struct routing_table *table, uint32_t network, uint8_t prefix_length, struct route_entry **routes, size_t *count);
void routing_table_print(const struct routing_table *table);
const char* route_type_to_string(route_type_t type);
char* ip_to_string(uint32_t ip, char *buffer);
#endif // ROUTING_H