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.

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