mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Fix TCP server regression.
onion.c was parsing recieved packets a bit too strictly and discarding packets that had ips with non valid families. TCP uses a non valid family to send back the packet to the proper connected node.
This commit is contained in:
parent
6650f18b86
commit
5e1d6f5183
|
@ -812,6 +812,7 @@ static int handle_TCP_packet(TCP_Server *TCP_server, uint32_t con_id, const uint
|
|||
source.port = 0; // dummy initialise
|
||||
source.ip.family = TCP_ONION_FAMILY;
|
||||
source.ip.ip6.uint32[0] = con_id;
|
||||
source.ip.ip6.uint32[1] = 0;
|
||||
source.ip.ip6.uint64[1] = con->identifier;
|
||||
onion_send_1(TCP_server->onion, data + 1 + crypto_box_NONCEBYTES, length - (1 + crypto_box_NONCEBYTES), source,
|
||||
data + 1);
|
||||
|
|
|
@ -61,7 +61,7 @@ static void ip_pack(uint8_t *data, IP source)
|
|||
}
|
||||
|
||||
/* return 0 on success, -1 on failure. */
|
||||
static int ip_unpack(IP *target, const uint8_t *data, unsigned int data_size)
|
||||
static int ip_unpack(IP *target, const uint8_t *data, unsigned int data_size, _Bool disable_family_check)
|
||||
{
|
||||
if (data_size < (1 + SIZE_IP6))
|
||||
return -1;
|
||||
|
@ -74,7 +74,12 @@ static int ip_unpack(IP *target, const uint8_t *data, unsigned int data_size)
|
|||
memcpy(target->ip6.uint8, data + 1, SIZE_IP6);
|
||||
}
|
||||
|
||||
return to_host_family(target);
|
||||
if (!disable_family_check) {
|
||||
return to_host_family(target);
|
||||
} else {
|
||||
to_host_family(target);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void ipport_pack(uint8_t *data, const IP_Port *source)
|
||||
|
@ -84,12 +89,12 @@ static void ipport_pack(uint8_t *data, const IP_Port *source)
|
|||
}
|
||||
|
||||
/* return 0 on success, -1 on failure. */
|
||||
static int ipport_unpack(IP_Port *target, const uint8_t *data, unsigned int data_size)
|
||||
static int ipport_unpack(IP_Port *target, const uint8_t *data, unsigned int data_size, _Bool disable_family_check)
|
||||
{
|
||||
if (data_size < (SIZE_IP + SIZE_PORT))
|
||||
return -1;
|
||||
|
||||
if (ip_unpack(&target->ip, data, data_size) == -1)
|
||||
if (ip_unpack(&target->ip, data, data_size, disable_family_check) == -1)
|
||||
return -1;
|
||||
|
||||
memcpy(&target->port, data + SIZE_IP, SIZE_PORT);
|
||||
|
@ -335,7 +340,7 @@ int onion_send_1(const Onion *onion, const uint8_t *plain, uint16_t len, IP_Port
|
|||
|
||||
IP_Port send_to;
|
||||
|
||||
if (ipport_unpack(&send_to, plain, len) == -1)
|
||||
if (ipport_unpack(&send_to, plain, len, 0) == -1)
|
||||
return 1;
|
||||
|
||||
uint8_t ip_port[SIZE_IPPORT];
|
||||
|
@ -385,7 +390,7 @@ static int handle_send_1(void *object, IP_Port source, const uint8_t *packet, ui
|
|||
|
||||
IP_Port send_to;
|
||||
|
||||
if (ipport_unpack(&send_to, plain, len) == -1)
|
||||
if (ipport_unpack(&send_to, plain, len, 0) == -1)
|
||||
return 1;
|
||||
|
||||
uint8_t data[ONION_MAX_PACKET_SIZE];
|
||||
|
@ -435,7 +440,7 @@ static int handle_send_2(void *object, IP_Port source, const uint8_t *packet, ui
|
|||
|
||||
IP_Port send_to;
|
||||
|
||||
if (ipport_unpack(&send_to, plain, len) == -1)
|
||||
if (ipport_unpack(&send_to, plain, len, 0) == -1)
|
||||
return 1;
|
||||
|
||||
uint8_t data[ONION_MAX_PACKET_SIZE];
|
||||
|
@ -482,7 +487,7 @@ static int handle_recv_3(void *object, IP_Port source, const uint8_t *packet, ui
|
|||
|
||||
IP_Port send_to;
|
||||
|
||||
if (ipport_unpack(&send_to, plain, len) == -1)
|
||||
if (ipport_unpack(&send_to, plain, len, 0) == -1)
|
||||
return 1;
|
||||
|
||||
uint8_t data[ONION_MAX_PACKET_SIZE];
|
||||
|
@ -518,7 +523,7 @@ static int handle_recv_2(void *object, IP_Port source, const uint8_t *packet, ui
|
|||
|
||||
IP_Port send_to;
|
||||
|
||||
if (ipport_unpack(&send_to, plain, len) == -1)
|
||||
if (ipport_unpack(&send_to, plain, len, 0) == -1)
|
||||
return 1;
|
||||
|
||||
uint8_t data[ONION_MAX_PACKET_SIZE];
|
||||
|
@ -554,7 +559,7 @@ static int handle_recv_1(void *object, IP_Port source, const uint8_t *packet, ui
|
|||
|
||||
IP_Port send_to;
|
||||
|
||||
if (ipport_unpack(&send_to, plain, len) == -1)
|
||||
if (ipport_unpack(&send_to, plain, len, 1) == -1)
|
||||
return 1;
|
||||
|
||||
uint16_t data_len = length - (1 + RETURN_1);
|
||||
|
|
Loading…
Reference in New Issue
Block a user