diff --git a/main.cpp b/main.cpp index dc28dfb..108cc97 100755 --- a/main.cpp +++ b/main.cpp @@ -1049,10 +1049,31 @@ int client_event_loop() u32_t dest_ip; string if_name_string; string hw_string; - if(find_lower_level_info(remote_ip_uint32,dest_ip,if_name_string,hw_string)!=0) + + if(retry_on_error==0) { - mylog(log_fatal,"auto detect lower-level info failed for %s,specific it manually\n",remote_ip); - myexit(-1); + 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()); @@ -1086,11 +1107,32 @@ int client_event_loop() if(source_ip_uint32==0) { mylog(log_info,"get_src_adress called\n"); - if(get_src_adress(source_ip_uint32,remote_ip_uint32,remote_port)!=0) + if(retry_on_error==0) { - mylog(log_fatal,"the trick to auto get source ip failed,you should specific an ip by --source-ip\n"); - myexit(-1); + if(get_src_adress(source_ip_uint32,remote_ip_uint32,remote_port)!=0) + { + 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; diff --git a/misc.cpp b/misc.cpp index 8a123a7..264d76d 100644 --- a/misc.cpp +++ b/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 length of heart-beat packet, >=0 and <=1500\n"); printf(" --mtu-warn 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; diff --git a/misc.h b/misc.h index 5415a90..95c9fda 100644 --- a/misc.h +++ b/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