summaryrefslogtreecommitdiff
path: root/ipmasq/rules/A01precompute.rul
blob: b1bc4ceef907e9c1052e0810c35d833a8237ef97 (plain)
  1. if [ "$SHOWRULES" = "yes" ]; then
  2. echo "Interfaces found:"
  3. fi
  4. # precompute ips and netmasks
  5. if [ -n "$EXTERNAL" -o -n "$INTERNAL" -o -n "$IPSEC" ]; then
  6. for i in $EXTERNAL $INTERNAL $IPSEC; do
  7. ii=$(echo $i | sed -e 's/\:/_/g')
  8. ip=$(ipofif $i)
  9. nm=$(nmofif $i)
  10. peer=$(peerofif $i)
  11. bc=$(bcofif $i)
  12. eval "IPOFIF_$ii=$ip"
  13. eval "NMOFIF_$ii=$nm"
  14. eval "PEEROFIF_$ii=$peer"
  15. eval "BCOFIF_$ii=$bc"
  16. if [ "$SHOWRULES" = "yes" ]; then
  17. /bin/echo -e " $i\t$ip/$nm"
  18. fi
  19. done
  20. fi
  21. # precompute ipsec connections
  22. if [ -n "$IPSEC" ]; then
  23. if [ "$SHOWRULES" = "yes" ]; then
  24. echo "IPSec connections found:"
  25. fi
  26. IPSECCONN=""
  27. for i in $IPSEC; do
  28. ii=$(echo $i | sed -e 's/\:/_/g')
  29. eval "ip=\$IPOFIF_$ii"
  30. eval "nm=\$IPOFIF_$ii"
  31. igw=$(ipsec look | grep IPIP:.*src=$ip | sed 's/^\([^[:blank:]]*\).*/\1/')
  32. conncollect=""
  33. for ipsecgw in $igw; do
  34. conn=$(ipsec look | grep "=> $ipsecgw" | sed 's/^.*=>[[:blank:]]*\([^@[:blank:]]*\).*/\1/')
  35. conncollect="$conncollect $conn"
  36. eval "IPSEC_IF_$conn=$i"
  37. cidrleft=$(ipsec look | grep "=> $ipsecgw" | sed 's/^\([^[:blank:]]*\)[[:blank:]]*->[[:blank:]]*[^[:blank:]]*.*/\1/')
  38. eval "IPSEC_HERE_$conn=$cidrleft"
  39. cidrright=$(ipsec look | grep "=> $ipsecgw" | sed 's/^[^[:blank:]]*[[:blank:]]*->[[:blank:]]*\([^[:blank:]]*\).*/\1/')
  40. eval "IPSEC_THERE_$conn=$cidrright"
  41. eval "IPSEC_THERE_$conn=$cidrright"
  42. done
  43. IPSECCONN="$IPSECCONN $conncollect"
  44. eval "IPSECCONN_${ii}=\"$conncollect\""
  45. if [ "$SHOWRULES" = "yes" ]; then
  46. /bin/echo -e " $i\t$ip/$nm"
  47. for conn in $conncollect; do
  48. eval "IPSEC_HERE=\$IPSEC_HERE_$conn"
  49. eval "IPSEC_THERE=\$IPSEC_THERE_$conn"
  50. /bin/echo -e " $IPSEC_HERE -> $IPSEC_THERE"
  51. done
  52. fi
  53. done
  54. fi