mirror of the now-defunct rocklinux.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
1.8 KiB

  1. iptables_init_if() {
  2. if isfirst "iptables_$if"; then
  3. addcode up 1 1 "iptables -N firewall_$if"
  4. addcode up 1 2 "iptables -A INPUT -i $if -j firewall_$if"
  5. addcode up 1 3 "iptables -A firewall_$if `
  6. `-m state --state ESTABLISHED,RELATED -j ACCEPT"
  7. addcode down 1 3 "iptables -F firewall_$if"
  8. addcode down 1 2 "iptables -D INPUT -i $if -j firewall_$if"
  9. addcode down 1 1 "iptables -X firewall_$if"
  10. fi
  11. }
  12. iptables_parse_conditions() {
  13. iptables_cond=""
  14. while [ -n "$1" ]
  15. do
  16. case "$1" in
  17. all)
  18. shift
  19. ;;
  20. tcp|udp)
  21. case "$2" in
  22. from)
  23. iptables_cond="$iptables_cond -p $1 --sport $3"
  24. shift; shift; shift;
  25. ;;
  26. *)
  27. iptables_cond="$iptables_cond -p $1 --dport $2"
  28. shift; shift
  29. ;;
  30. esac
  31. ;;
  32. icmp)
  33. iptables_cond="$iptables_cond -p icmp --icmp-type $2"
  34. shift; shift
  35. ;;
  36. ip)
  37. iptables_cond="$iptables_cond -s $2"
  38. shift; shift
  39. ;;
  40. *)
  41. error "Unkown accept/reject/drop condition: $1"
  42. shift
  43. esac
  44. done
  45. }
  46. public_accept() {
  47. iptables_parse_conditions "$@"
  48. addcode up 1 5 "iptables -A firewall_$if $iptables_cond -j ACCEPT"
  49. iptables_init_if
  50. }
  51. public_reject() {
  52. iptables_parse_conditions "$@"
  53. addcode up 1 5 "iptables -A firewall_$if $iptables_cond -j REJECT"
  54. iptables_init_if
  55. }
  56. public_drop() {
  57. iptables_parse_conditions "$@"
  58. addcode up 1 5 "iptables -A firewall_$if $iptables_cond -j DROP"
  59. iptables_init_if
  60. }
  61. public_clamp_mtu() {
  62. addcode up 1 6 "iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN \
  63. -j TCPMSS --clamp-mss-to-pmtu"
  64. addcode down 9 6 "iptables -D FORWARD -p tcp --tcp-flags SYN,RST SYN \
  65. -j TCPMSS --clamp-mss-to-pmtu"
  66. }
  67. public_masquerade() {
  68. addcode up 1 6 "iptables -t nat -A POSTROUTING -o $if \
  69. -j MASQUERADE"
  70. addcode down 9 6 "iptables -t nat -D POSTROUTING -o $if \
  71. -j MASQUERADE"
  72. }