Skip to content

Commit

Permalink
move some code to server side, fixed some log level
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyu- committed Oct 28, 2017
1 parent becd952 commit a622a46
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
2 changes: 1 addition & 1 deletion UDPspeeder
Submodule UDPspeeder updated 2 files
+11 −1 misc.cpp
+2 −0 misc.h
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cc_mips24kc_le=/toolchains/lede-sdk-17.01.2-ramips-mt7621_gcc-5.4.0_musl-1.1.16.
#cc_arm= /toolchains/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabi/bin/arm-linux-gnueabi-g++ -march=armv6 -marm
cc_arm= /toolchains/arm-2014.05/bin/arm-none-linux-gnueabi-g++
#cc_bcm2708=/home/wangyu/raspberry/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++
FLAGS= -std=c++11 -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter -Wno-missing-field-initializers -ggdb -I. -IUDPspeeder
FLAGS= -std=c++11 -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter -Wno-missing-field-initializers -ggdb -I. -IUDPspeeder ${OPT}

SOURCES=`ls UDPspeeder/*.cpp UDPspeeder/lib/*.c|grep -v main.cpp|grep -v tunnel.cpp` main.cpp tun_dev.cpp

Expand Down
44 changes: 30 additions & 14 deletions tun_dev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,24 @@ int from_fec_to_normal2(conn_info_t & conn_info,dest_t &dest,char * data,int len
for(int i=0;i<out_n;i++)
{
delay_send(out_delay[i],dest,out_arr[i],out_len[i]);

#ifndef NORES
char * tmp_data=out_arr[i];
int tmp_len=out_len[i];
if(tmp_len>=20)
{
u32_t dest_ip=htonl(read_u32(tmp_data+16));
//printf("%s\n",my_ntoa(dest_ip));
if( ( ntohl(sub_net_uint32)&0xFFFFFF00 ) != ( ntohl (dest_ip) &0xFFFFFF00) )
{
string sub=my_ntoa(dest_ip);
string dst=my_ntoa( htonl( ntohl (sub_net_uint32) &0xFFFFFF00) );
mylog(log_warn,"[restriction]packet's dest ip [%s] not in subnet [%s],dropped\n", sub.c_str(), dst.c_str());
continue;
}
}
#endif

}

return 0;
Expand Down Expand Up @@ -293,17 +311,6 @@ int tun_dev_client_event_loop()
mylog(log_warn,"read from tun_fd return %d,errno=%s\n",len,strerror(errno));
continue;
}
if(len>=20)
{
u32_t dest_ip=htonl(read_u32(data+16));
if( ( ntohl(sub_net_uint32)&0xFFFFFF00 ) != ( ntohl (dest_ip) &0xFFFFFF00) )
{
string sub=my_ntoa(dest_ip);
string dst=my_ntoa( htonl( ntohl (dest_ip) &0xFFFFFF00) );
mylog(log_warn,"packet's dest ip [%s] not in subnet [%s],dropped\n", sub.c_str(), dst.c_str());
continue;
}
}

mylog(log_trace,"Received packet from tun,len: %d\n",len);

Expand Down Expand Up @@ -340,8 +347,17 @@ int tun_dev_client_event_loop()

if(header==header_reject)
{
mylog(log_fatal,"server restarted or switched to handle another client,exited\n");
myexit(-1);
if(keep_reconnect==0)
{
mylog(log_fatal,"server restarted or switched to handle another client,exited\n");
myexit(-1);
}
else
{
if(got_feed_back==1)
mylog(log_warn,"server restarted or switched to handle another client,but keep-reconnect enable,trying to reconnect\n");
got_feed_back=0;
}
continue;
}
else if(header==header_normal)
Expand Down Expand Up @@ -597,7 +613,7 @@ int tun_dev_server_event_loop()
}
else if(header==header_normal)
{
mylog(log_info,"rejected connection from %s:%d\n", inet_ntoa(udp_new_addr_in.sin_addr),ntohs(udp_new_addr_in.sin_port));
mylog(log_debug,"rejected connection from %s:%d\n", inet_ntoa(udp_new_addr_in.sin_addr),ntohs(udp_new_addr_in.sin_port));


len=1;
Expand Down

0 comments on commit a622a46

Please sign in to comment.