1
This commit is contained in:
1 parent
b1c8ba7e90
commit
0e9a91729c
9 files changed
+195
-21
No files matched your search
@@ -9,6 +9,7 @@
|
||||
#include "etcp.h"
|
||||
#include "etcp_connections.h"
|
||||
#include "tun_if.h"
|
||||
#include "route_lib.h"
|
||||
#include "../lib/u_async.h"
|
||||
#include "../lib/debug_config.h"
|
||||
#include "../lib/mem.h"
|
||||
@@ -767,6 +768,27 @@ static void send_metrics(struct control_server* server, struct control_client* c
|
||||
rsp->tun.packets_written = instance->tun->packets_written;
|
||||
rsp->tun.read_errors = instance->tun->read_errors;
|
||||
rsp->tun.write_errors = instance->tun->write_errors;
|
||||
|
||||
/* Routing statistics */
|
||||
rsp->tun.routed_packets = instance->routed_packets;
|
||||
rsp->tun.dropped_packets = instance->dropped_packets;
|
||||
|
||||
/* TUN queues */
|
||||
rsp->tun.tun_in_q_packets = (uint32_t)queue_entry_count(instance->tun->input_queue);
|
||||
rsp->tun.tun_in_q_bytes = (uint32_t)queue_total_bytes(instance->tun->input_queue);
|
||||
rsp->tun.tun_out_q_packets = (uint32_t)queue_entry_count(instance->tun->output_queue);
|
||||
rsp->tun.tun_out_q_bytes = (uint32_t)queue_total_bytes(instance->tun->output_queue);
|
||||
|
||||
/* Routing table */
|
||||
if (instance->rt) {
|
||||
rsp->tun.rt_count = (uint32_t)instance->rt->count;
|
||||
rsp->tun.rt_local = (uint32_t)instance->rt->stats.local_routes;
|
||||
rsp->tun.rt_learned = (uint32_t)instance->rt->stats.learned_routes;
|
||||
} else {
|
||||
rsp->tun.rt_count = 0;
|
||||
rsp->tun.rt_local = 0;
|
||||
rsp->tun.rt_learned = 0;
|
||||
}
|
||||
} else {
|
||||
memset(&rsp->tun, 0, sizeof(rsp->tun));
|
||||
}
|
||||
|
||||
@@ -114,6 +114,7 @@ static void route_pkt(struct UTUN_INSTANCE* instance, struct ll_entry* entry) {
|
||||
struct ROUTE_ARRAY* routes = route_table_lookup(instance->rt, dst_ip);
|
||||
if (!routes || routes->routes == 0) {
|
||||
DEBUG_INFO(DEBUG_CATEGORY_ROUTING, "route_pkt: no route to %s, dropping", ip_to_str(&addr, AF_INET).str);
|
||||
instance->dropped_packets++;
|
||||
queue_entry_free(entry);
|
||||
queue_dgram_free(entry);
|
||||
return;
|
||||
@@ -124,11 +125,13 @@ static void route_pkt(struct UTUN_INSTANCE* instance, struct ll_entry* entry) {
|
||||
// Local route - send to TUN (entry has [cmd=0][IP data], TUN skips cmd byte)
|
||||
if (queue_data_put(instance->tun->input_queue, entry, 0) != 0) {
|
||||
DEBUG_WARN(DEBUG_CATEGORY_ROUTING, "route_pkt: failed to put to TUN input_queue");
|
||||
instance->dropped_packets++;
|
||||
queue_entry_free(entry);
|
||||
queue_dgram_free(entry);
|
||||
return;
|
||||
}
|
||||
// Entry sent to TUN, don't free here
|
||||
instance->routed_packets++;
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_ROUTING, "route_pkt: sent %zu bytes to TUN", ip_len);
|
||||
return;
|
||||
}
|
||||
@@ -137,6 +140,7 @@ static void route_pkt(struct UTUN_INSTANCE* instance, struct ll_entry* entry) {
|
||||
struct ETCP_CONN* conn = routes->entries[0]->next_hop;
|
||||
if (!conn) {
|
||||
DEBUG_WARN(DEBUG_CATEGORY_ROUTING, "route_pkt: route to %s has no next_hop, dropping", ip_to_str(&addr, AF_INET).str);
|
||||
instance->dropped_packets++;
|
||||
queue_entry_free(entry);
|
||||
queue_dgram_free(entry);
|
||||
return;
|
||||
@@ -144,6 +148,7 @@ static void route_pkt(struct UTUN_INSTANCE* instance, struct ll_entry* entry) {
|
||||
|
||||
if (!conn->normalizer) {
|
||||
DEBUG_WARN(DEBUG_CATEGORY_ROUTING, "route_pkt: connection for %s has no normalizer, dropping", ip_to_str(&addr, AF_INET).str);
|
||||
instance->dropped_packets++;
|
||||
queue_entry_free(entry);
|
||||
queue_dgram_free(entry);
|
||||
return;
|
||||
@@ -153,12 +158,14 @@ static void route_pkt(struct UTUN_INSTANCE* instance, struct ll_entry* entry) {
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_ROUTING, "route_pkt: sending %zu bytes to ETCP %s", ip_len, conn->log_name);
|
||||
if (etcp_send(conn, entry) != 0) {
|
||||
DEBUG_WARN(DEBUG_CATEGORY_ROUTING, "route_pkt: etcp_send failed for %s", ip_to_str(&addr, AF_INET).str);
|
||||
instance->dropped_packets++;
|
||||
queue_entry_free(entry);
|
||||
queue_dgram_free(entry);
|
||||
return;
|
||||
}
|
||||
|
||||
// Entry sent successfully, don't free here
|
||||
instance->routed_packets++;
|
||||
}
|
||||
|
||||
// Callback for packets from ETCP (via etcp_bind id=0)
|
||||
|
||||
@@ -56,6 +56,10 @@ struct UTUN_INSTANCE {
|
||||
// Active sockets
|
||||
struct ETCP_SOCKET* etcp_sockets;// linked-list
|
||||
|
||||
// Routing statistics
|
||||
uint64_t routed_packets;
|
||||
uint64_t dropped_packets;
|
||||
|
||||
// ETCP API bindings (per-instance)
|
||||
struct ETCP_BINDINGS api_bindings;
|
||||
|
||||
|
||||
Reference in new issue
Block a user