mirror of
https://github.com/wangyu-/udp2raw.git
synced 2025-01-19 14:29:34 +08:00
new option --retry-on-error
This commit is contained in:
parent
0711c7355f
commit
2362f28eb6
44
main.cpp
44
main.cpp
@ -1049,11 +1049,32 @@ int client_event_loop()
|
||||
u32_t dest_ip;
|
||||
string if_name_string;
|
||||
string hw_string;
|
||||
|
||||
if(retry_on_error==0)
|
||||
{
|
||||
if(find_lower_level_info(remote_ip_uint32,dest_ip,if_name_string,hw_string)!=0)
|
||||
{
|
||||
mylog(log_fatal,"auto detect lower-level info failed for %s,specific it manually\n",remote_ip);
|
||||
myexit(-1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int ok=0;
|
||||
while(!ok)
|
||||
{
|
||||
if(find_lower_level_info(remote_ip_uint32,dest_ip,if_name_string,hw_string)!=0)
|
||||
{
|
||||
mylog(log_warn,"auto detect lower-level info failed for %s,retry in %d seconds\n",remote_ip,retry_on_error_interval);
|
||||
sleep(retry_on_error_interval);
|
||||
}
|
||||
else
|
||||
{
|
||||
ok=1;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
mylog(log_info,"we are running at lower-level (auto) mode,%s %s %s\n",my_ntoa(dest_ip),if_name_string.c_str(),hw_string.c_str());
|
||||
|
||||
u32_t hw[6];
|
||||
@ -1086,12 +1107,33 @@ int client_event_loop()
|
||||
if(source_ip_uint32==0)
|
||||
{
|
||||
mylog(log_info,"get_src_adress called\n");
|
||||
if(retry_on_error==0)
|
||||
{
|
||||
if(get_src_adress(source_ip_uint32,remote_ip_uint32,remote_port)!=0)
|
||||
{
|
||||
mylog(log_fatal,"the trick to auto get source ip failed,you should specific an ip by --source-ip\n");
|
||||
mylog(log_fatal,"the trick to auto get source ip failed, maybe you dont have internet\n");
|
||||
myexit(-1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int ok=0;
|
||||
while(!ok)
|
||||
{
|
||||
if(get_src_adress(source_ip_uint32,remote_ip_uint32,remote_port)!=0)
|
||||
{
|
||||
mylog(log_warn,"the trick to auto get source ip failed, maybe you dont have internet, retry in %d seconds\n",retry_on_error_interval);
|
||||
sleep(retry_on_error_interval);
|
||||
}
|
||||
else
|
||||
{
|
||||
ok=1;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
in_addr tmp;
|
||||
tmp.s_addr=source_ip_uint32;
|
||||
mylog(log_info,"source ip = %s\n",inet_ntoa(tmp));
|
||||
|
8
misc.cpp
8
misc.cpp
@ -44,6 +44,8 @@ int auto_add_iptables_rule=0;//if -a is set
|
||||
int generate_iptables_rule=0;//if -g is set
|
||||
int generate_iptables_rule_add=0;// if --gen-add is set
|
||||
|
||||
int retry_on_error=0;
|
||||
|
||||
int debug_resend=0; // debug only
|
||||
|
||||
char key_string[1000]= "secret key";// -k option
|
||||
@ -163,6 +165,7 @@ void print_help()
|
||||
printf(" --hb-len <number> length of heart-beat packet, >=0 and <=1500\n");
|
||||
printf(" --mtu-warn <number> mtu warning threshold, unit:byte, default:1375\n");
|
||||
printf(" --clear clear any iptables rules added by this program.overrides everything\n");
|
||||
printf(" --retry-on-error retry on error, allow to start udp2raw before network is initialized\n");
|
||||
printf(" -h,--help print this help message\n");
|
||||
|
||||
//printf("common options,these options must be same on both side\n");
|
||||
@ -250,6 +253,7 @@ void process_arg(int argc, char *argv[]) //process all options
|
||||
{"gen-rule", no_argument, 0, 'g'},
|
||||
{"gen-add", no_argument, 0, 1},
|
||||
{"debug", no_argument, 0, 1},
|
||||
{"retry-on-error", no_argument, 0, 1},
|
||||
{"clear", no_argument, 0, 1},
|
||||
{"simple-rule", no_argument, 0, 1},
|
||||
{"keep-rule", no_argument, 0, 1},
|
||||
@ -544,6 +548,10 @@ void process_arg(int argc, char *argv[]) //process all options
|
||||
{
|
||||
force_socket_buf=1;
|
||||
}
|
||||
else if(strcmp(long_options[option_index].name,"retry-on-error")==0)
|
||||
{
|
||||
retry_on_error=1;
|
||||
}
|
||||
else if(strcmp(long_options[option_index].name,"wait-lock")==0)
|
||||
{
|
||||
wait_xtables_lock=1;
|
||||
|
2
misc.h
2
misc.h
@ -87,6 +87,8 @@ extern int keep_rule; //whether to monitor the iptables rule periodly,re-add if
|
||||
extern int auto_add_iptables_rule;//if -a is set
|
||||
extern int generate_iptables_rule;//if -g is set
|
||||
extern int generate_iptables_rule_add;// if --gen-add is set
|
||||
extern int retry_on_error;
|
||||
const int retry_on_error_interval=10;
|
||||
|
||||
extern int debug_resend; // debug only
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user