mirror of
https://github.com/rofl0r/proxychains-ng
synced 2025-01-09 23:02:52 +08:00
change unsocksify_udp_packet() and
decapsulate_udp_packet() signature. Moved udp data copy outside these functions
This commit is contained in:
parent
81092b1f4b
commit
a47f9c0576
15
src/core.c
15
src/core.c
@ -740,7 +740,7 @@ int is_from_chain_head(udp_relay_chain chain, struct sockaddr* src_addr){
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
int decapsulate_check_udp_packet(void* in_buffer, size_t in_buffer_len, udp_relay_chain chain, socks5_addr* src_addr, unsigned short* src_port, void* udp_data, size_t* udp_data_len){
|
int decapsulate_check_udp_packet(void* in_buffer, size_t in_buffer_len, udp_relay_chain chain, socks5_addr* src_addr, unsigned short* src_port, void** udp_data){
|
||||||
|
|
||||||
PFUNC();
|
PFUNC();
|
||||||
// Go through the whole proxy chain, decapsulate each header and check that the addresses match
|
// Go through the whole proxy chain, decapsulate each header and check that the addresses match
|
||||||
@ -794,22 +794,19 @@ int decapsulate_check_udp_packet(void* in_buffer, size_t in_buffer_len, udp_rela
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Copy the UDP data to the provided buffer. If the provided buffer is too small, data is truncated
|
// Point udp_data to the position of the UDP data inside in_buffer
|
||||||
int min = ((in_buffer_len-read)>*udp_data_len)?*udp_data_len:(in_buffer_len-read);
|
*udp_data = in_buffer+read;
|
||||||
memcpy(udp_data,in_buffer+read, min);
|
|
||||||
|
|
||||||
// Write back the length of written UDP data in the input/output parameter udp_data_len
|
|
||||||
*udp_data_len = min;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int unsocksify_udp_packet(void* in_buffer, size_t in_buffer_len, udp_relay_chain chain, ip_type* src_ip, unsigned short* src_port, void* udp_data, size_t* udp_data_len){
|
//Takes an in_buffer of size in_buffer_len, checks that all UDP headers are correct (against chain), fills src_ip and src_port with address of the peer sending the packet through the relay, and fills udp_data with the address of the udp data inside in_buff
|
||||||
|
int unsocksify_udp_packet(void* in_buffer, size_t in_buffer_len, udp_relay_chain chain, ip_type* src_ip, unsigned short* src_port, void** udp_data){
|
||||||
PFUNC();
|
PFUNC();
|
||||||
// Decapsulate all the UDP headers and check that the packet came from the right proxy nodes
|
// Decapsulate all the UDP headers and check that the packet came from the right proxy nodes
|
||||||
int rc;
|
int rc;
|
||||||
socks5_addr src_addr;
|
socks5_addr src_addr;
|
||||||
rc = decapsulate_check_udp_packet(in_buffer, in_buffer_len, chain, &src_addr, src_port, udp_data, udp_data_len);
|
rc = decapsulate_check_udp_packet(in_buffer, in_buffer_len, chain, &src_addr, src_port, udp_data);
|
||||||
if(rc != SUCCESS){
|
if(rc != SUCCESS){
|
||||||
PDEBUG("error decapsulating the packet\n");
|
PDEBUG("error decapsulating the packet\n");
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -222,7 +222,7 @@ size_t get_msg_iov_total_len(struct iovec* iov, size_t iov_len);
|
|||||||
size_t write_buf_to_iov(void* buff, size_t buff_len, struct iovec* iov, size_t iov_len);
|
size_t write_buf_to_iov(void* buff, size_t buff_len, struct iovec* iov, size_t iov_len);
|
||||||
size_t write_iov_to_buf(void* buff, size_t buff_len, struct iovec* iov, size_t iov_len);
|
size_t write_iov_to_buf(void* buff, size_t buff_len, struct iovec* iov, size_t iov_len);
|
||||||
int is_from_chain_head(udp_relay_chain chain, struct sockaddr* src_addr);
|
int is_from_chain_head(udp_relay_chain chain, struct sockaddr* src_addr);
|
||||||
int unsocksify_udp_packet(void* in_buffer, size_t in_buffer_len, udp_relay_chain chain, ip_type* src_ip, unsigned short* src_port, void* udp_data, size_t* udp_data_len);
|
int unsocksify_udp_packet(void* in_buffer, size_t in_buffer_len, udp_relay_chain chain, ip_type* src_ip, unsigned short* src_port, void** udp_data);
|
||||||
int socksify_udp_packet(void* udp_data, size_t udp_data_len, udp_relay_chain chain, ip_type dst_ip, unsigned short dst_port, void* buffer, size_t* buffer_len);
|
int socksify_udp_packet(void* udp_data, size_t udp_data_len, udp_relay_chain chain, ip_type dst_ip, unsigned short dst_port, void* buffer, size_t* buffer_len);
|
||||||
int encapsulate_udp_packet(udp_relay_chain chain, socks5_addr dst_addr, unsigned short dst_port, void* buffer, size_t* buffer_len);
|
int encapsulate_udp_packet(udp_relay_chain chain, socks5_addr dst_addr, unsigned short dst_port, void* buffer, size_t* buffer_len);
|
||||||
void set_connected_peer_addr(udp_relay_chain* chain, struct sockaddr* addr, socklen_t addrlen);
|
void set_connected_peer_addr(udp_relay_chain* chain, struct sockaddr* addr, socklen_t addrlen);
|
||||||
|
@ -1811,16 +1811,16 @@ HOOKFUNC(ssize_t, recvmsg, int sockfd, struct msghdr *msg, int flags){
|
|||||||
int rc;
|
int rc;
|
||||||
ip_type src_ip;
|
ip_type src_ip;
|
||||||
unsigned short src_port;
|
unsigned short src_port;
|
||||||
char udp_data[RECV_BUFFER_SIZE];
|
void* udp_data = NULL;
|
||||||
size_t udp_data_len = sizeof(udp_data);
|
size_t udp_data_len = 0;
|
||||||
|
|
||||||
rc = unsocksify_udp_packet(buffer, bytes_received, *relay_chain, &src_ip, &src_port, udp_data, &udp_data_len);
|
rc = unsocksify_udp_packet(buffer, bytes_received, *relay_chain, &src_ip, &src_port, &udp_data);
|
||||||
if(rc != SUCCESS){
|
if(rc != SUCCESS){
|
||||||
PDEBUG("error unSOCKSing the UDP packet\n");
|
PDEBUG("error unSOCKSing the UDP packet\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
PDEBUG("UDP packet successfully unSOCKified\n");
|
PDEBUG("UDP packet successfully unSOCKified\n");
|
||||||
|
udp_data_len = bytes_received - (udp_data - (void*)buffer);
|
||||||
|
|
||||||
/*debug*/
|
/*debug*/
|
||||||
DEBUGDECL(char str[256]);
|
DEBUGDECL(char str[256]);
|
||||||
@ -1975,24 +1975,30 @@ HOOKFUNC(ssize_t, recvfrom, int sockfd, void *buf, size_t len, int flags,
|
|||||||
PDEBUG("packet received from the proxy chain's head\n");
|
PDEBUG("packet received from the proxy chain's head\n");
|
||||||
|
|
||||||
int rc;
|
int rc;
|
||||||
size_t udp_data_len = len;
|
void* udp_data = NULL;
|
||||||
rc = unsocksify_udp_packet(tmp_buffer, bytes_received, *relay_chain, &src_ip, &src_port, buf, &udp_data_len);
|
size_t udp_data_len = 0;
|
||||||
|
rc = unsocksify_udp_packet(tmp_buffer, bytes_received, *relay_chain, &src_ip, &src_port, &udp_data);
|
||||||
if(rc != SUCCESS){
|
if(rc != SUCCESS){
|
||||||
PDEBUG("error unsocksifying the UDP packet\n");
|
PDEBUG("error unsocksifying the UDP packet\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
PDEBUG("UDP packet successfully unsocksifyied\n");
|
PDEBUG("UDP packet successfully unsocksifyied\n");
|
||||||
|
udp_data_len = bytes_received - (udp_data - (void*)tmp_buffer);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PDEBUG("received %d bytes through receive_udp_packet()\n", udp_data_len);
|
PDEBUG("received %d bytes through receive_udp_packet()\n", udp_data_len);
|
||||||
PDEBUG("data: ");
|
PDEBUG("data: ");
|
||||||
DUMP_BUFFER(buf, udp_data_len);
|
DUMP_BUFFER(udp_data, udp_data_len);
|
||||||
PDEBUG("from_addr: ");
|
PDEBUG("from_addr: ");
|
||||||
DUMP_BUFFER(src_ip.addr.v6, src_ip.is_v6?16:4);
|
DUMP_BUFFER(src_ip.addr.v6, src_ip.is_v6?16:4);
|
||||||
PDEBUG("from_addr: %s\n", inet_ntop(src_ip.is_v6 ? AF_INET6 : AF_INET, src_ip.is_v6 ? (void*)src_ip.addr.v6 : (void*)src_ip.addr.v4.octet, str, sizeof(str)));
|
PDEBUG("from_addr: %s\n", inet_ntop(src_ip.is_v6 ? AF_INET6 : AF_INET, src_ip.is_v6 ? (void*)src_ip.addr.v6 : (void*)src_ip.addr.v4.octet, str, sizeof(str)));
|
||||||
PDEBUG("from_port: %hu\n", ntohs(src_port));
|
PDEBUG("from_port: %hu\n", ntohs(src_port));
|
||||||
|
|
||||||
|
// Copy received UDP data to the buffer provided by the client
|
||||||
|
size_t min = (udp_data_len < len)?udp_data_len:len;
|
||||||
|
memcpy(buf, udp_data, min);
|
||||||
|
|
||||||
// WARNING : Est ce que si le client avait envoyé des packets UDP avec resolution DNS dans le socks,
|
// WARNING : Est ce que si le client avait envoyé des packets UDP avec resolution DNS dans le socks,
|
||||||
// on doit lui filer comme address source pour les packets recu l'addresse de mapping DNS ? Si oui comment
|
// on doit lui filer comme address source pour les packets recu l'addresse de mapping DNS ? Si oui comment
|
||||||
// la retrouver ? -> done in unsocksify_udp_packet()
|
// la retrouver ? -> done in unsocksify_udp_packet()
|
||||||
|
Loading…
Reference in New Issue
Block a user