|
|
|
|
@ -91,7 +91,8 @@ static void raw_read_cb(socket_t sock, void* arg) {
|
|
|
|
|
if (icmp_hdr->icmp_type != ICMP_ECHOREPLY) return; |
|
|
|
|
|
|
|
|
|
struct icmp_request* r = req_find_by_id(g_icmp_ctx->pending, icmp_hdr->icmp_id, icmp_hdr->icmp_seq); |
|
|
|
|
if (!r) return; |
|
|
|
|
if (!r) { DEBUG_WARN(DEBUG_CATEGORY_SOCKET, "icmp_proxy: unclaimed echo reply id=0x%04x seq=%u from=0x%08x", |
|
|
|
|
icmp_hdr->icmp_id, icmp_hdr->icmp_seq, from.sin_addr.s_addr); return; } |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_SOCKET, "icmp_proxy: echo reply id=0x%04x seq=%u from=0x%08x", |
|
|
|
|
icmp_hdr->icmp_id, icmp_hdr->icmp_seq, from.sin_addr.s_addr); |
|
|
|
|
|
|
|
|
|
@ -111,7 +112,9 @@ static void raw_read_cb(socket_t sock, void* arg) {
|
|
|
|
|
memcpy(e->dgram + 16, &icmp_hdr->icmp_seq, 2); |
|
|
|
|
if (payload_len > 0) memcpy(e->dgram + ICMP_PROXY_HDR_SIZE, payload, payload_len); |
|
|
|
|
e->len = ICMP_PROXY_HDR_SIZE + payload_len; |
|
|
|
|
etcp_route_send(g_icmp_ctx->inst, r->client_node_id, e); |
|
|
|
|
int ret = etcp_route_send(g_icmp_ctx->inst, r->client_node_id, e); |
|
|
|
|
if (ret != 0) DEBUG_ERROR(DEBUG_CATEGORY_SOCKET, "icmp_proxy: etcp_route_send reply failed: %d", ret); |
|
|
|
|
else DEBUG_INFO(DEBUG_CATEGORY_SOCKET, "icmp_proxy: reply forwarded to client %016llx", (unsigned long long)r->client_node_id); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ====================================================================
|
|
|
|
|
@ -165,6 +168,8 @@ static void client_handle_reply(struct ETCP_CONN* conn, struct ll_entry* entry)
|
|
|
|
|
memcpy(&src_ip, entry->dgram + 10, 4); |
|
|
|
|
memcpy(&echo_id, entry->dgram + 14, 2); |
|
|
|
|
memcpy(&echo_seq, entry->dgram + 16, 2); |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_SOCKET, "icmp_proxy: client got reply id=0x%04x seq=%u from=0x%08x", |
|
|
|
|
echo_id, echo_seq, src_ip); |
|
|
|
|
struct UTUN_INSTANCE* inst = conn ? conn->instance : (g_icmp_ctx ? g_icmp_ctx->inst : NULL); |
|
|
|
|
icmp_proxy_deliver_reply(inst, src_ip, echo_id, echo_seq, |
|
|
|
|
entry->dgram + ICMP_PROXY_HDR_SIZE, entry->len - ICMP_PROXY_HDR_SIZE); |
|
|
|
|
@ -213,7 +218,11 @@ int icmp_proxy_send_to_exit(struct UTUN_INSTANCE* inst, uint64_t exit_node_id,
|
|
|
|
|
int icmp_proxy_deliver_reply(struct UTUN_INSTANCE* inst, |
|
|
|
|
uint32_t src_ip, uint16_t echo_id, uint16_t echo_seq, |
|
|
|
|
const uint8_t* payload, size_t payload_len) { |
|
|
|
|
if (!inst || !inst->tcp_proxy || !inst->tcp_proxy->tun) return -1; |
|
|
|
|
if (!inst || !inst->tcp_proxy || !inst->tcp_proxy->tun) { |
|
|
|
|
DEBUG_ERROR(DEBUG_CATEGORY_SOCKET, "icmp_proxy: deliver_reply failed — no %s", |
|
|
|
|
!inst ? "inst" : !inst->tcp_proxy ? "tcp_proxy" : "TUN"); |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
struct tun_if* tun = inst->tcp_proxy->tun; |
|
|
|
|
uint32_t dst_ip = inst->tcp_proxy->tun_ip_addr; |
|
|
|
|
|
|
|
|
|
@ -245,6 +254,7 @@ int icmp_proxy_deliver_reply(struct UTUN_INSTANCE* inst,
|
|
|
|
|
e->dgram[0] = 4; memcpy(e->dgram + 1, pkt, pkt_len); e->len = 1 + pkt_len; |
|
|
|
|
u_free(pkt); |
|
|
|
|
queue_data_put(tun->output_queue, e); |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_SOCKET, "icmp_proxy: reply delivered to TUN id=0x%04x seq=%u", echo_id, echo_seq); |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|