1717
1818IPTABLES=${IPTABLES:-/ sbin/ iptables} 
1919SLEEP_INTERVAL=${SLEEP_INTERVAL:- 10} 
20+ WAIT_INTERVAL=${WAIT_INTERVAL:- 60} 
2021CONFIG_DIR=${CONFIG_DIR:-/ cfg} 
2122if  [[ -z  ${UUID:- }  ]];  then 
2223  UUID=$( date " +%s" ) 
@@ -37,7 +38,7 @@ update_nat() {
3738  #  Check if the rule already exists if adding.
3839  if  [[ ${mode}  =  ' A' ;  then 
3940    if  ${IPTABLES}  -t nat -C POSTROUTING -d ${subnet}  \
40-         -m comment --comment " ${comment} " 
41+         -m comment --comment " ${comment} " -w  ${WAIT_INTERVAL} \
4142        2> /dev/null;  then 
4243      log " NAT rule ${comment}  is installed" 
4344      return 
@@ -49,7 +50,7 @@ update_nat() {
4950    -${mode}  POSTROUTING \
5051    -d ${subnet}  \
5152    -m comment --comment " ${comment} " 
52-     -j MASQUERADE
53+     -j MASQUERADE -w  ${WAIT_INTERVAL} 
5354
5455  case  ${mode}  in 
5556    ' A' " NAT rule ${comment}  added" 
@@ -73,16 +74,28 @@ main() {
7374    #  Remove the old NAT rules if config file has changed.
7475    if  [[ " ${old_nat_rules} " !=  " ${nat_rules} " ;  then 
7576      log " Configuration change detected" 
76-       for  subnet  in  ${old_nat_rules} ;  do 
77-         update_nat D ${subnet}  " ${COMMENT_PREFIX} : ${subnet} " 
77+       n=0
78+       until  [ " $n " -ge  5 ]
79+       do 
80+         (for subnet in  ${old_nat_rules} ;  do 
81+           update_nat D ${subnet}  " ${COMMENT_PREFIX} : ${subnet} " 
82+         done) &&  break 
83+         n=$(( n+ 1 )) 
84+         sleep 5
7885      done 
7986    fi 
8087
8188    if  [[ -z  " ${nat_rules} " ;  then 
8289      log " No NAT rules configured" 
8390    else 
84-       for  subnet  in  ${old_nat_rules} ;  do 
85-         update_nat A ${subnet}  " ${COMMENT_PREFIX} : ${subnet} " 
91+       n=0
92+       until  [ " $n " -ge  5 ]
93+       do 
94+         (for subnet in  ${old_nat_rules} ;  do 
95+           update_nat A ${subnet}  " ${COMMENT_PREFIX} : ${subnet} " 
96+         done) &&  break 
97+         n=$(( n+ 1 )) 
98+         sleep 5
8699      done 
87100    fi 
88101
0 commit comments