mirror of
https://github.com/wangyu-/udp2raw.git
synced 2025-01-19 14:29:34 +08:00
reduce diff
This commit is contained in:
parent
8331610e7a
commit
c72480110f
12
client.cpp
12
client.cpp
@ -10,7 +10,6 @@
|
||||
|
||||
int client_on_timer(conn_info_t &conn_info) //for client. called when a timer is ready in epoll
|
||||
{
|
||||
//keep_iptables_rule();
|
||||
packet_info_t &send_info=conn_info.raw_info.send_info;
|
||||
packet_info_t &recv_info=conn_info.raw_info.recv_info;
|
||||
raw_info_t &raw_info=conn_info.raw_info;
|
||||
@ -117,7 +116,6 @@ int client_on_timer(conn_info_t &conn_info) //for client. called when a timer is
|
||||
mylog(log_info,"state changed from client_idle to client_tcp_handshake\n");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
conn_info.last_state_time=get_current_time();
|
||||
conn_info.last_hb_sent_time=0;
|
||||
@ -321,7 +319,6 @@ int client_on_raw_recv(conn_info_t &conn_info) //called when raw fd received a p
|
||||
|
||||
if(conn_info.state.client_current_state==client_idle )
|
||||
{
|
||||
|
||||
discard_raw_packet();
|
||||
//recv(raw_recv_fd, 0,0, 0 );
|
||||
}
|
||||
@ -354,7 +351,6 @@ int client_on_raw_recv(conn_info_t &conn_info) //called when raw fd received a p
|
||||
mylog(log_info,"state changed from client_tcp_dummy to client_handshake1\n");
|
||||
//send_info.ack_seq=recv_info.seq+1;
|
||||
}
|
||||
|
||||
conn_info.state.client_current_state = client_handshake1;
|
||||
|
||||
conn_info.last_state_time = get_current_time();
|
||||
@ -385,17 +381,14 @@ int client_on_raw_recv(conn_info_t &conn_info) //called when raw fd received a p
|
||||
mylog(log_debug,"too short to be a handshake\n");
|
||||
return -1;
|
||||
}
|
||||
//id_t tmp_oppsite_id= ntohl(* ((u32_t *)&data[0]));
|
||||
my_id_t tmp_oppsite_id;
|
||||
memcpy(&tmp_oppsite_id,&data[0],sizeof(tmp_oppsite_id));
|
||||
tmp_oppsite_id=ntohl(tmp_oppsite_id);
|
||||
|
||||
//id_t tmp_my_id=ntohl(* ((u32_t *)&data[sizeof(id_t)]));
|
||||
my_id_t tmp_my_id;
|
||||
memcpy(&tmp_my_id,&data[sizeof(my_id_t)],sizeof(tmp_my_id));
|
||||
tmp_my_id=ntohl(tmp_my_id);
|
||||
|
||||
//id_t tmp_oppsite_const_id=ntohl(* ((u32_t *)&data[sizeof(id_t)*2]));
|
||||
my_id_t tmp_oppsite_const_id;
|
||||
memcpy(&tmp_oppsite_const_id,&data[sizeof(my_id_t)*2],sizeof(tmp_oppsite_const_id));
|
||||
tmp_oppsite_const_id=ntohl(tmp_oppsite_const_id);
|
||||
@ -424,7 +417,6 @@ int client_on_raw_recv(conn_info_t &conn_info) //called when raw fd received a p
|
||||
|
||||
mylog(log_info,"changed state from to client_handshake1 to client_handshake2,my_id is %x,oppsite id is %x\n",conn_info.my_id,conn_info.oppsite_id);
|
||||
|
||||
//send_handshake(raw_info,conn_info.my_id,conn_info.oppsite_id,const_id); //////////////send
|
||||
conn_info.state.client_current_state = client_handshake2;
|
||||
conn_info.last_state_time = get_current_time();
|
||||
conn_info.last_hb_sent_time=0;
|
||||
@ -467,7 +459,6 @@ int client_on_raw_recv(conn_info_t &conn_info) //called when raw fd received a p
|
||||
if(hb_mode==0)
|
||||
conn_info.last_hb_recv_time=get_current_time();
|
||||
|
||||
//u32_t tmp_conv_id= ntohl(* ((u32_t *)&data[0]));
|
||||
u32_t tmp_conv_id;
|
||||
memcpy(&tmp_conv_id,&data[0],sizeof(tmp_conv_id));
|
||||
tmp_conv_id=ntohl(tmp_conv_id);
|
||||
@ -481,7 +472,6 @@ int client_on_raw_recv(conn_info_t &conn_info) //called when raw fd received a p
|
||||
conn_info.blob->conv_manager.c.update_active_time(tmp_conv_id);
|
||||
|
||||
//u64_t u64=conn_info.blob->conv_manager.c.find_data_by_conv(tmp_conv_id);
|
||||
|
||||
address_t tmp_addr=conn_info.blob->conv_manager.c.find_data_by_conv(tmp_conv_id);
|
||||
|
||||
//sockaddr_in tmp_sockaddr={0};
|
||||
@ -542,7 +532,6 @@ int client_on_udp_recv(conn_info_t &conn_info)
|
||||
tmp_addr.from_sockaddr((sockaddr *)&udp_new_addr_in,udp_new_addr_len);
|
||||
u32_t conv;
|
||||
|
||||
//u64_t u64;//////todo
|
||||
if(!conn_info.blob->conv_manager.c.is_data_used(tmp_addr))
|
||||
{
|
||||
if(conn_info.blob->conv_manager.c.get_size() >=max_conv_num)
|
||||
@ -788,6 +777,5 @@ int client_event_loop()
|
||||
}
|
||||
|
||||
ev_run(loop, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
22
common.cpp
22
common.cpp
@ -9,9 +9,10 @@
|
||||
#include "log.h"
|
||||
#include "misc.h"
|
||||
|
||||
#include <random>
|
||||
#include <cmath>
|
||||
|
||||
//static int random_number_fd=-1;
|
||||
|
||||
int force_socket_buf=0;
|
||||
|
||||
int address_t::from_str(char *str)
|
||||
@ -322,15 +323,12 @@ int my_ip_t::from_address_t(address_t tmp_addr)
|
||||
int my_ip_t::from_str(char * str)
|
||||
{
|
||||
u32_t type;
|
||||
|
||||
if(strchr(str,':')==NULL)
|
||||
type=AF_INET;
|
||||
else
|
||||
type=AF_INET6;
|
||||
|
||||
int ret;
|
||||
ret=inet_pton(type, str,this);
|
||||
|
||||
if(ret==0) // 0 if address type doesnt match
|
||||
{
|
||||
mylog(log_error,"confusion in parsing %s, %d\n",str,ret);
|
||||
@ -454,7 +452,6 @@ u64_t get_true_random_number_64()
|
||||
mylog(log_fatal,"get random number failed %d\n",size);
|
||||
myexit(-1);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
u32_t get_true_random_number()
|
||||
@ -478,6 +475,11 @@ u32_t get_true_random_number_nz() //nz for non-zero
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline int is_big_endian()
|
||||
{
|
||||
int i=1;
|
||||
return ! *((char *)&i);
|
||||
}
|
||||
u64_t ntoh64(u64_t a)
|
||||
{
|
||||
#ifdef UDP2RAW_LITTLE_ENDIAN
|
||||
@ -495,7 +497,6 @@ u64_t hton64(u64_t a)
|
||||
return ntoh64(a);
|
||||
}
|
||||
|
||||
|
||||
void write_u16(char * p,u16_t w)
|
||||
{
|
||||
*(unsigned char*)(p + 1) = (w & 0xff);
|
||||
@ -562,7 +563,6 @@ void setnonblocking(int sock) {
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Generic checksum calculation function
|
||||
*/
|
||||
@ -641,12 +641,12 @@ int set_buf_size(int fd,int socket_buf_size)
|
||||
{
|
||||
if(setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &socket_buf_size, sizeof(socket_buf_size))<0)
|
||||
{
|
||||
mylog(log_fatal,"SO_SNDBUF fail socket_buf_size=%d errno=%s\n",socket_buf_size,strerror(errno));
|
||||
mylog(log_fatal,"SO_SNDBUF fail socket_buf_size=%d errno=%s\n",socket_buf_size,get_sock_error());
|
||||
myexit(1);
|
||||
}
|
||||
if(setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &socket_buf_size, sizeof(socket_buf_size))<0)
|
||||
{
|
||||
mylog(log_fatal,"SO_RCVBUF fail socket_buf_size=%d errno=%s\n",socket_buf_size,strerror(errno));
|
||||
mylog(log_fatal,"SO_RCVBUF fail socket_buf_size=%d errno=%s\n",socket_buf_size,get_sock_error());
|
||||
myexit(1);
|
||||
}
|
||||
}
|
||||
@ -1096,7 +1096,6 @@ void print_binary_chars(const char * a,int len)
|
||||
log_bare(log_debug,"\n");
|
||||
}
|
||||
|
||||
|
||||
u32_t djb2(unsigned char *str,int len)
|
||||
{
|
||||
u32_t hash = 5381;
|
||||
@ -1123,6 +1122,3 @@ u32_t sdbm(unsigned char *str,int len)
|
||||
//hash=htonl(hash);
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -9,7 +9,6 @@
|
||||
#include "encrypt.h"
|
||||
#include "fd_manager.h"
|
||||
|
||||
|
||||
int disable_anti_replay=0;//if anti_replay windows is diabled
|
||||
|
||||
|
||||
@ -346,7 +345,6 @@ int conn_manager_t::clear_inactive0()
|
||||
|
||||
|
||||
|
||||
|
||||
int send_bare(raw_info_t &raw_info,const char* data,int len)//send function with encryption but no anti replay,this is used when client and server verifys each other
|
||||
//you have to design the protocol carefully, so that you wont be affect by relay attack
|
||||
{
|
||||
@ -594,7 +592,8 @@ int reserved_parse_safer(conn_info_t &conn_info,const char * input,int input_len
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(0==1);
|
||||
mylog(log_fatal,"unknow hb_mode\n");
|
||||
myexit(-1);
|
||||
}
|
||||
|
||||
|
||||
|
@ -30,7 +30,8 @@ void fd_manager_t::fd64_close(fd64_t fd64)
|
||||
{
|
||||
fd_info_mp.erase(fd64);
|
||||
}
|
||||
assert(close(fd)==0);
|
||||
//assert(close(fd)==0);
|
||||
sock_close(fd);
|
||||
}
|
||||
void fd_manager_t::reserve(int n)
|
||||
{
|
||||
|
16
main.cpp
16
main.cpp
@ -26,23 +26,9 @@ void sigint_cb(struct ev_loop *l, ev_signal *w, int revents)
|
||||
|
||||
int client_event_loop();
|
||||
int server_event_loop();
|
||||
/*
|
||||
int test()
|
||||
{
|
||||
|
||||
char ip_str[100]="8.8.8.8";
|
||||
u32_t ip=inet_addr(ip_str);
|
||||
u32_t dest_ip;
|
||||
string if_name;
|
||||
string hw;
|
||||
find_lower_level_info(ip,dest_ip,if_name,hw);
|
||||
printf("%s %s %s\n",my_ntoa(dest_ip),if_name.c_str(),hw.c_str());
|
||||
exit(0);
|
||||
return 0;
|
||||
}*/
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
assert(sizeof(unsigned short)==2);
|
||||
assert(sizeof(unsigned int)==4);
|
||||
assert(sizeof(unsigned long long)==8);
|
||||
@ -79,7 +65,6 @@ int main(int argc, char *argv[])
|
||||
signal(SIGTERM, signal_handler);
|
||||
signal(SIGQUIT, signal_handler);
|
||||
}
|
||||
|
||||
#if !defined(__MINGW32__)
|
||||
if(geteuid() != 0)
|
||||
{
|
||||
@ -91,7 +76,6 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
mylog(log_info,"remote_ip=[%s], make sure this is a vaild IP address\n",remote_addr.get_ip());
|
||||
|
||||
//init_random_number_fd();
|
||||
|
20
misc.cpp
20
misc.cpp
@ -15,10 +15,8 @@
|
||||
|
||||
int hb_mode=1;
|
||||
int hb_len=1200;
|
||||
|
||||
char hb_buf[buf_len];
|
||||
|
||||
|
||||
int mtu_warn=1375;//if a packet larger than mtu warn is receviced,there will be a warning
|
||||
|
||||
int max_rst_to_show=15;
|
||||
@ -91,6 +89,8 @@ int about_to_exit=0;
|
||||
|
||||
|
||||
int socket_buf_size=1024*1024;
|
||||
//int force_socket_buf=0;
|
||||
|
||||
|
||||
|
||||
//char lower_level_arg[1000];
|
||||
@ -129,7 +129,6 @@ void print_help()
|
||||
printf("udp2raw-tunnel\n");
|
||||
printf("git version:%s ",git_version_buf);
|
||||
printf("build date:%s %s\n",__DATE__,__TIME__);
|
||||
|
||||
printf("repository: https://github.com/wangyu-/udp2raw-tunnel\n");
|
||||
printf("\n");
|
||||
printf("usage:\n");
|
||||
@ -199,7 +198,7 @@ int load_config(char *file_name, int &argc, vector<string> &argv) //load conf fi
|
||||
std::string line;
|
||||
if(conf_file.fail())
|
||||
{
|
||||
mylog(log_fatal,"conf_file %s open failed,reason :%s\n",file_name,strerror(errno));
|
||||
mylog(log_fatal,"conf_file %s open failed,reason :%s\n",file_name,get_sock_error());
|
||||
myexit(-1);
|
||||
}
|
||||
while(std::getline(conf_file,line))
|
||||
@ -419,7 +418,6 @@ void process_arg(int argc, char *argv[]) //process all options
|
||||
} else {
|
||||
mylog(log_fatal,"invalid parameter for -l ,%s,should be ip:port\n",optarg);
|
||||
myexit(-1);
|
||||
|
||||
}*/
|
||||
break;
|
||||
case 'r':
|
||||
@ -483,7 +481,6 @@ void process_arg(int argc, char *argv[]) //process all options
|
||||
{
|
||||
clear_iptables=1;
|
||||
}
|
||||
|
||||
else if(strcmp(long_options[option_index].name,"source-ip")==0)
|
||||
{
|
||||
mylog(log_debug,"parsing long option :source-ip\n");
|
||||
@ -604,6 +601,10 @@ void process_arg(int argc, char *argv[]) //process all options
|
||||
{
|
||||
//enable_log_color=0;
|
||||
}
|
||||
else if(strcmp(long_options[option_index].name,"enable-color")==0)
|
||||
{
|
||||
//enable_log_color=0;
|
||||
}
|
||||
else if(strcmp(long_options[option_index].name,"debug")==0)
|
||||
{
|
||||
debug_flag=1;
|
||||
@ -768,9 +769,6 @@ void process_arg(int argc, char *argv[]) //process all options
|
||||
raw_ip_version=local_addr.get_type();
|
||||
}
|
||||
|
||||
//if(lower_level)
|
||||
//process_lower_level_arg();
|
||||
|
||||
mylog(log_info,"important variables: ");
|
||||
|
||||
log_bare(log_info,"log_level=%d:%s ",log_level,log_text[log_level]);
|
||||
@ -1191,7 +1189,6 @@ int set_timer_server(int epollfd,int &timer_fd,fd64_t &fd64)//only for server
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int handle_lower_level(raw_info_t &raw_info)//fill lower_level info,when --lower-level is enabled,only for server
|
||||
{
|
||||
packet_info_t &send_info=raw_info.send_info;
|
||||
@ -1363,6 +1360,3 @@ void signal_handler(int sig)
|
||||
about_to_exit=1;
|
||||
// myexit(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user