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.

73 lines
1.7 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. iptables_cond="$iptables_cond -p $1 --dport $2"
  22. shift; shift
  23. ;;
  24. icmp)
  25. iptables_cond="$iptables_cond -p icmp --icmp-type $2"
  26. shift; shift
  27. ;;
  28. ip)
  29. iptables_cond="$iptables_cond -s $2"
  30. shift; shift
  31. ;;
  32. *)
  33. error "Unkown accept/reject/drop condition: $1"
  34. shift
  35. esac
  36. done
  37. }
  38. public_accept() {
  39. iptables_parse_conditions "$@"
  40. addcode up 1 5 "iptables -A firewall_$if $iptables_cond -j ACCEPT"
  41. iptables_init_if
  42. }
  43. public_reject() {
  44. iptables_parse_conditions "$@"
  45. addcode up 1 5 "iptables -A firewall_$if $iptables_cond -j REJECT"
  46. iptables_init_if
  47. }
  48. public_drop() {
  49. iptables_parse_conditions "$@"
  50. addcode up 1 5 "iptables -A firewall_$if $iptables_cond -j DROP"
  51. iptables_init_if
  52. }
  53. public_clamp_mtu() {
  54. addcode up 1 6 "iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN \
  55. -j TCPMSS --clamp-mss-to-pmtu"
  56. addcode down 9 6 "iptables -D FORWARD -p tcp --tcp-flags SYN,RST SYN \
  57. -j TCPMSS --clamp-mss-to-pmtu"
  58. }
  59. public_masquerade() {
  60. addcode up 1 6 "iptables -t nat -A POSTROUTING -o $if \
  61. -j MASQUERADE"
  62. addcode down 9 6 "iptables -t nat -D POSTROUTING -o $if \
  63. -j MASQUERADE"
  64. }