Saltstack Official IPTables Formula
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # This file is managed by SaltStack
  2. {%- for table in ['mangle', 'nat', 'filter'] %}
  3. *{{ table }}
  4. {%- for chain_name, chain in chains.iteritems() %}
  5. :{{ chain_name | upper }} {{ chain.get('policy', '-') | upper }}
  6. {%- endfor %}
  7. {%- for chain_name, chain in chains.iteritems() %}
  8. {%- for rule in chain.rules %}
  9. {%- if rule.get('table', 'filter').lower() == table and rule.get('family', 'ipv4') == 'ipv4' %}
  10. {%- set r = {
  11. 'full': 'True',
  12. 'table': table,
  13. 'chain': chain_name.upper(),
  14. 'command': 'A',
  15. 'family': 'ipv4',
  16. 'comment': rule.get('comment', '') + '__saltstack__',
  17. } %}
  18. {%- if rule.position is defined %}
  19. {%- do r.update({
  20. 'command': 'I',
  21. 'position': rule['position'],
  22. }) %}
  23. {%- endif %}
  24. {%- if rule.jump is defined %}
  25. {%- do r.update({'jump': rule.jump}) %}
  26. {%- endif %}
  27. {%- if rule.match is defined %}
  28. {%- do r.update({'match': rule.match}) %}
  29. {%- endif %}
  30. {%- if rule.connection_state is defined %}
  31. {%- do r.update({'connstate': rule.connection_state}) %}
  32. {%- endif %}
  33. {%- if rule.protocol is defined %}
  34. {%- do r.update({'proto': rule.protocol}) %}
  35. {%- endif %}
  36. {%- if rule.destination_port is defined %}
  37. {%- do r.update({'dport': rule.destination_port}) %}
  38. {%- endif %}
  39. {%- if rule.source_port is defined %}
  40. {%- do r.update({'sport': rule.source_port}) %}
  41. {%- endif %}
  42. {%- if rule.in_interface is defined %}
  43. {%- do r.update({'in-interface': rule.in_interface}) %}
  44. {%- endif %}
  45. {%- if rule.out_interface is defined %}
  46. {%- do r.update({'out-interface': rule.out_interface}) %}
  47. {%- endif %}
  48. {%- if rule.to_destination is defined %}
  49. {%- do r.update({'to-destination': rule.to_destination}) %}
  50. {%- endif %}
  51. {%- if rule.to_port is defined %}
  52. {%- do r.update({'to-port': rule.to_port}) %}
  53. {%- endif %}
  54. {%- if rule.to_source is defined %}
  55. {%- do r.update({'to-source': rule.to_source}) %}
  56. {%- endif %}
  57. {%- if rule.source_network is defined %}
  58. {%- do r.update({'source': rule.source_network}) %}
  59. {%- endif %}
  60. {%- if rule.destination_network is defined %}
  61. {%- do r.update({'destination': rule.destination_network}) %}
  62. {%- endif %}
  63. {%- if rule.mark is defined %}
  64. {%- do r.update({'mark': rule.mark}) %}
  65. {%- endif %}
  66. {%- if rule.set_mark is defined %}
  67. {%- do r.update({'set-mark': rule.set_mark}) %}
  68. {%- endif %}
  69. {{ salt['iptables.build_rule'](**r) | regex_replace('^.*-t %s ' % table, '') }}
  70. {%- endif %}
  71. {%- endfor %}
  72. {%- endfor %}
  73. COMMIT
  74. {%- endfor %}