firewall.awk 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # Copyright (C) 2006 OpenWrt.org
  2. BEGIN {
  3. FS=":"
  4. }
  5. ($1 == "accept") || ($1 == "drop") || ($1 == "forward") {
  6. delete _opt
  7. str2data($2)
  8. if ((_l["proto"] == "") && (_l["sport"] _l["dport"] != "")) {
  9. _opt[0] = " -p tcp"
  10. _opt[1] = " -p udp"
  11. } else {
  12. _opt[0] = ""
  13. }
  14. }
  15. ($1 == "accept") {
  16. target = " -j ACCEPT"
  17. for (o in _opt) {
  18. print "iptables -t nat -A prerouting_wan" _opt[o] str2ipt($2) target
  19. print "iptables -A input_wan " _opt[o] str2ipt($2) target
  20. print ""
  21. }
  22. }
  23. ($1 == "drop") {
  24. for (o in _opt) {
  25. print "iptables -t nat -A prerouting_wan" _opt[o] str2ipt($2) " -j DROP"
  26. print ""
  27. }
  28. }
  29. ($1 == "forward") {
  30. target = " -j DNAT --to " $3
  31. fwopts = ""
  32. if ($4 != "") {
  33. if ((_l["proto"] == "tcp") || (_l["proto"] == "udp") || (_l["proto"] == "")) {
  34. if (_l["proto"] != "") fwopts = " -p " _l["proto"]
  35. fwopts = fwopts " --dport " $4
  36. target = target ":" $4
  37. }
  38. else fwopts = ""
  39. }
  40. for (o in _opt) {
  41. print "iptables -t nat -A prerouting_wan" _opt[o] str2ipt($2) target
  42. print "iptables -A forwarding_wan " _opt[o] " -d " $3 fwopts " -j ACCEPT"
  43. print ""
  44. }
  45. }