seq mode 3 and 4,include git version in help page

This commit is contained in:
wangyu- 2017-09-06 05:31:29 -05:00
parent 178327c581
commit 9472fe8bb3
4 changed files with 88 additions and 26 deletions

View File

@ -3,6 +3,7 @@
#include "log.h" #include "log.h"
#include "lib/md5.h" #include "lib/md5.h"
#include "encrypt.h" #include "encrypt.h"
#include "git_version.h"
#include <fstream> #include <fstream>
#include <string> #include <string>
#include <vector> #include <vector>
@ -2579,8 +2580,11 @@ int process_lower_level_arg()//handle --lower-level option
} }
void print_help() void print_help()
{ {
char git_version_buf[100]={0};
strncpy(git_version_buf,gitversion,10);
printf("udp2raw-tunnel\n"); printf("udp2raw-tunnel\n");
printf("version: %s %s\n",__DATE__,__TIME__); printf("build date:%s %s\n",__DATE__,__TIME__);
printf("git version: %s\n",git_version_buf);
printf("repository: https://github.com/wangyu-/udp2raw-tunnel\n"); printf("repository: https://github.com/wangyu-/udp2raw-tunnel\n");
printf("\n"); printf("\n");
printf("usage:\n"); printf("usage:\n");
@ -2617,9 +2621,12 @@ void print_help()
printf(" --sock-buf <number> buf size for socket,>=10 and <=10240,unit:kbyte,default:1024\n"); printf(" --sock-buf <number> buf size for socket,>=10 and <=10240,unit:kbyte,default:1024\n");
printf(" --force-sock-buf bypass system limitation while setting sock-buf\n"); printf(" --force-sock-buf bypass system limitation while setting sock-buf\n");
printf(" --seqmode <number> seq increase mode for faketcp:\n"); printf(" --seqmode <number> seq increase mode for faketcp:\n");
printf(" 0:dont increase\n"); printf(" 0:static header,do not increase seq and ack_seq\n");
printf(" 1:increase every packet(default)\n"); printf(" 1:increase seq for every packet,simply ack last seq\n");
printf(" 2:increase randomly, about every 3 packets\n"); printf(" 2:increase seq randomly, about every 3 packets,simply ack last seq\n");
printf(" 3:simulate an almost real seq/ack procedure(default)\n");
printf(" 4:similiar to 3,but do not consider TCP Option Window_Scale,\n");
printf(" maybe useful when firewall doesnt support TCP Option \n");
// printf("\n"); // printf("\n");
printf(" --lower-level <string> send packets at OSI level 2, format:'if_name#dest_mac_adress'\n"); printf(" --lower-level <string> send packets at OSI level 2, format:'if_name#dest_mac_adress'\n");
printf(" ie:'eth0#00:23:45:67:89:b9'.or try '--lower-level auto' to obtain\n"); printf(" ie:'eth0#00:23:45:67:89:b9'.or try '--lower-level auto' to obtain\n");
@ -3063,7 +3070,7 @@ void process_arg(int argc, char *argv[]) //process all options
else if(strcmp(long_options[option_index].name,"seq-mode")==0) else if(strcmp(long_options[option_index].name,"seq-mode")==0)
{ {
sscanf(optarg,"%d",&seq_mode); sscanf(optarg,"%d",&seq_mode);
if(0<=seq_mode&&seq_mode<=3) if(0<=seq_mode&&seq_mode<=max_seq_mode)
{ {
} }
else else

View File

@ -13,48 +13,48 @@ NAME=udp2raw
TARGETS=amd64 mips34kc arm amd64_hw_aes arm_asm_aes mips34kc_asm_aes x86 x86_asm_aes TARGETS=amd64 mips34kc arm amd64_hw_aes arm_asm_aes mips34kc_asm_aes x86 x86_asm_aes
TAR=${NAME}_binaries.tar.gz `echo ${TARGETS}|sed -r 's/([^ ]+)/udp2raw_\1/g'` TAR=${NAME}_binaries.tar.gz `echo ${TARGETS}|sed -r 's/([^ ]+)/udp2raw_\1/g'`
all: all:git_version
rm -f ${NAME} rm -f ${NAME}
${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -lrt -ggdb -static -O3 ${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -lrt -ggdb -static -O3
fast: fast: git_version
rm -f ${NAME} rm -f ${NAME}
${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -lrt -ggdb ${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -lrt -ggdb
debug: debug: git_version
rm -f ${NAME} rm -f ${NAME}
${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -lrt -Wformat-nonliteral -D MY_DEBUG ${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -lrt -Wformat-nonliteral -D MY_DEBUG
debug2: debug2: git_version
rm -f ${NAME} rm -f ${NAME}
${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -lrt -Wformat-nonliteral -ggdb ${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -lrt -Wformat-nonliteral -ggdb
mips34kc: mips34kc: git_version
${cc_mips34kc} -o ${NAME}_$@ -I. ${SOURCES} ${FLAGS} -lrt -lgcc_eh -static -O3 ${cc_mips34kc} -o ${NAME}_$@ -I. ${SOURCES} ${FLAGS} -lrt -lgcc_eh -static -O3
mips34kc_asm_aes: mips34kc_asm_aes: git_version
${cc_mips34kc} -o ${NAME}_$@ -I. ${SOURCES_AES_ACC} ${FLAGS} -lrt -lgcc_eh -static -O3 lib/aes_acc/asm/mips_be.S ${cc_mips34kc} -o ${NAME}_$@ -I. ${SOURCES_AES_ACC} ${FLAGS} -lrt -lgcc_eh -static -O3 lib/aes_acc/asm/mips_be.S
#bcm2708: #bcm2708:
# ${cc_bcm2708} -o ${NAME}_bcm2708 -I. ${SOURCES} ${FLAGS} -lrt -static -O3 # ${cc_bcm2708} -o ${NAME}_bcm2708 -I. ${SOURCES} ${FLAGS} -lrt -static -O3
amd64: amd64:git_version
${cc_local} -o ${NAME}_$@ -I. ${SOURCES} ${FLAGS} -lrt -static -O3 ${cc_local} -o ${NAME}_$@ -I. ${SOURCES} ${FLAGS} -lrt -static -O3
amd64_hw_aes: amd64_hw_aes:git_version
${cc_local} -o ${NAME}_$@ -I. ${SOURCES_AES_ACC} ${FLAGS} -lrt -static -O3 lib/aes_acc/asm/x64.S ${cc_local} -o ${NAME}_$@ -I. ${SOURCES_AES_ACC} ${FLAGS} -lrt -static -O3 lib/aes_acc/asm/x64.S
x86: x86:git_version
${cc_local} -o ${NAME}_$@ -I. ${SOURCES} ${FLAGS} -lrt -static -O3 -m32 ${cc_local} -o ${NAME}_$@ -I. ${SOURCES} ${FLAGS} -lrt -static -O3 -m32
x86_asm_aes: x86_asm_aes:git_version
${cc_local} -o ${NAME}_$@ -I. ${SOURCES_AES_ACC} ${FLAGS} -lrt -static -O3 -m32 lib/aes_acc/asm/x86.S ${cc_local} -o ${NAME}_$@ -I. ${SOURCES_AES_ACC} ${FLAGS} -lrt -static -O3 -m32 lib/aes_acc/asm/x86.S
arm: arm:git_version
${cc_arm} -o ${NAME}_$@ -I. ${SOURCES} ${FLAGS} -lrt -static -O3 ${cc_arm} -o ${NAME}_$@ -I. ${SOURCES} ${FLAGS} -lrt -static -O3
arm_asm_aes: arm_asm_aes:git_version
${cc_arm} -o ${NAME}_$@ -I. ${SOURCES_AES_ACC} ${FLAGS} -lrt -static -O3 lib/aes_acc/asm/arm.S ${cc_arm} -o ${NAME}_$@ -I. ${SOURCES_AES_ACC} ${FLAGS} -lrt -static -O3 lib/aes_acc/asm/arm.S
cross: cross:git_version
${cc_cross} -o ${NAME}_cross -I. ${SOURCES} ${FLAGS} -lrt -O3 ${cc_cross} -o ${NAME}_cross -I. ${SOURCES} ${FLAGS} -lrt -O3
cross2: cross2:git_version
${cc_cross} -o ${NAME}_cross -I. ${SOURCES} ${FLAGS} -lrt -static -lgcc_eh -O3 ${cc_cross} -o ${NAME}_cross -I. ${SOURCES} ${FLAGS} -lrt -static -lgcc_eh -O3
cross3: cross3:git_version
${cc_cross} -o ${NAME}_cross -I. ${SOURCES} ${FLAGS} -lrt -static -O3 ${cc_cross} -o ${NAME}_cross -I. ${SOURCES} ${FLAGS} -lrt -static -O3
release: ${TARGETS} release: ${TARGETS}
@ -63,4 +63,8 @@ release: ${TARGETS}
clean: clean:
rm -f ${TAR} rm -f ${TAR}
rm -f udp2raw udp2raw_cross udp2raw_cmake rm -f udp2raw udp2raw_cross udp2raw_cmake
rm -f git_version.h
git_version:
echo "const char *gitversion = \"$(shell git rev-parse HEAD)\";" > git_version.h

View File

@ -12,7 +12,8 @@ int raw_recv_fd=-1;
int raw_send_fd=-1; int raw_send_fd=-1;
u32_t link_level_header_len=0;//set it to 14 if SOCK_RAW is used in socket(PF_PACKET, SOCK_RAW, htons(ETH_P_IP)); u32_t link_level_header_len=0;//set it to 14 if SOCK_RAW is used in socket(PF_PACKET, SOCK_RAW, htons(ETH_P_IP));
int seq_mode=1; int seq_mode=3;
int max_seq_mode=4;
int filter_port=-1; int filter_port=-1;
@ -31,6 +32,10 @@ unsigned char dest_hw_addr[sizeof(sockaddr_ll::sll_addr)]=
{0xff,0xff,0xff,0xff,0xff,0xff,0,0}; {0xff,0xff,0xff,0xff,0xff,0xff,0,0};
//{0x00,0x23,0x45,0x67,0x89,0xb9}; //{0x00,0x23,0x45,0x67,0x89,0xb9};
const u32_t receive_window_lower_bound=40960;
const u32_t receive_window_random_range=512;
const unsigned char wscale=0x05;
struct sock_filter code_tcp_old[] = { struct sock_filter code_tcp_old[] = {
{ 0x28, 0, 0, 0x0000000c },//0 { 0x28, 0, 0, 0x0000000c },//0
{ 0x15, 0, 10, 0x00000800 },//1 { 0x15, 0, 10, 0x00000800 },//1
@ -146,6 +151,7 @@ packet_info_t::packet_info_t()
ts_ack=0; ts_ack=0;
syn=0; syn=0;
ack=1; ack=1;
ack_seq_counter=0;
//mylog(log_info,"<cons ,ts_ack= %u>\n",ts_ack); //mylog(log_info,"<cons ,ts_ack= %u>\n",ts_ack);
} }
@ -925,7 +931,7 @@ int send_raw_tcp(raw_info_t &raw_info,const char * payload, int payloadlen) {
send_raw_tcp_buf[i++] = 0x01; send_raw_tcp_buf[i++] = 0x01;
send_raw_tcp_buf[i++] = 0x03; send_raw_tcp_buf[i++] = 0x03;
send_raw_tcp_buf[i++] = 0x03; send_raw_tcp_buf[i++] = 0x03;
send_raw_tcp_buf[i++] = 0x05; send_raw_tcp_buf[i++] = wscale;
} else { } else {
tcph->doff = 8; tcph->doff = 8;
int i = sizeof(pseudo_header)+sizeof(tcphdr); int i = sizeof(pseudo_header)+sizeof(tcphdr);
@ -954,7 +960,7 @@ int send_raw_tcp(raw_info_t &raw_info,const char * payload, int payloadlen) {
tcph->urg = 0; tcph->urg = 0;
//tcph->window = htons((uint16_t)(1024)); //tcph->window = htons((uint16_t)(1024));
tcph->window = htons((uint16_t) (10240 + random() % 100)); tcph->window = htons((uint16_t) (receive_window_lower_bound + random() % receive_window_random_range));
tcph->check = 0; //leave checksum 0 now, filled later by pseudo header tcph->check = 0; //leave checksum 0 now, filled later by pseudo header
tcph->urg_ptr = 0; tcph->urg_ptr = 0;
@ -1413,7 +1419,20 @@ int recv_raw_tcp(raw_info_t &raw_info,char * &payload,int &payloadlen)
recv_info.dst_port=ntohs(tcph->dest); recv_info.dst_port=ntohs(tcph->dest);
recv_info.seq=ntohl(tcph->seq); recv_info.seq=ntohl(tcph->seq);
// recv_info.last_last_ack_seq=recv_info.last_ack_seq;
//recv_info.last_ack_seq=recv_info.ack_seq;
u32_t last_ack_seq=recv_info.ack_seq;
recv_info.ack_seq=ntohl(tcph->ack_seq); recv_info.ack_seq=ntohl(tcph->ack_seq);
if(recv_info.ack_seq==last_ack_seq)
{
recv_info.ack_seq_counter++;
}
else
{
recv_info.ack_seq_counter=0;
}
recv_info.psh=tcph->psh; recv_info.psh=tcph->psh;
if(tcph->rst==1) if(tcph->rst==1)
@ -1649,6 +1668,35 @@ int after_send_raw0(raw_info_t &raw_info)
if (random() % 5 == 3) if (random() % 5 == 3)
send_info.seq += raw_info.send_info.data_len; //////////////////modify send_info.seq += raw_info.send_info.data_len; //////////////////modify
} }
else if(seq_mode==3||seq_mode==4)
{
send_info.seq += raw_info.send_info.data_len;
u32_t window_size;
if(seq_mode==3)
{
window_size=(u32_t)((u32_t)receive_window_lower_bound<<(u32_t)wscale);
}
else//seq_mode==4
{
window_size=(u32_t)((u32_t)receive_window_lower_bound);
}
if(larger_than_u32(send_info.seq+max_data_len,recv_info.ack_seq+window_size))
{
send_info.seq=raw_info.recv_info.ack_seq;
}
if(recv_info.ack_seq_counter>=3)
{
recv_info.ack_seq_counter=0;
send_info.seq=raw_info.recv_info.ack_seq;
}
if(larger_than_u32(raw_info.recv_info.ack_seq,send_info.seq)) //for further use,currently not useful.
{
send_info.seq=raw_info.recv_info.ack_seq;
}
}
} }
} }
if(raw_mode==mode_icmp) if(raw_mode==mode_icmp)
@ -1676,11 +1724,12 @@ int after_recv_raw0(raw_info_t &raw_info)
if(larger_than_u32(recv_info.seq+raw_info.recv_info.data_len,send_info.ack_seq)) if(larger_than_u32(recv_info.seq+raw_info.recv_info.data_len,send_info.ack_seq))
send_info.ack_seq = recv_info.seq+raw_info.recv_info.data_len;//TODO only update if its larger send_info.ack_seq = recv_info.seq+raw_info.recv_info.data_len;//TODO only update if its larger
} }
else if(seq_mode==3) else if(seq_mode==3||seq_mode==4)
{ {
if(recv_info.seq==send_info.ack_seq+1) if(recv_info.seq==send_info.ack_seq)
{ {
send_info.ack_seq=recv_info.seq+raw_info.recv_info.data_len; send_info.ack_seq=recv_info.seq+raw_info.recv_info.data_len;//currently we dont remembr tcp segments,this is the simplest way
//TODO implement tcp segment remembering and SACK.
} }
} }
} }

View File

@ -11,6 +11,7 @@
extern int raw_recv_fd; extern int raw_recv_fd;
extern int raw_send_fd; extern int raw_send_fd;
extern int seq_mode; extern int seq_mode;
extern int max_seq_mode;
extern int filter_port; extern int filter_port;
extern u32_t bind_address_uint32; extern u32_t bind_address_uint32;
extern int disable_bpf_filter; extern int disable_bpf_filter;
@ -54,6 +55,7 @@ struct packet_info_t //todo change this to union
u32_t seq,ack_seq; u32_t seq,ack_seq;
u32_t ack_seq_counter;
u32_t ts,ts_ack; u32_t ts,ts_ack;