|
4 | 4 | Do not edit this file manually, it will be overwritten!
|
5 | 5 | Modify the salt pillar for firewalld instead
|
6 | 6 | -->
|
| 7 | +{%- macro rich_rule(rule) -%} |
| 8 | + {%- if 'family' in rule %} |
| 9 | + <rule family="{{ rule.family }}"> |
| 10 | + {%- else %} |
| 11 | + <rule> |
| 12 | + {%- endif %} |
| 13 | + {%- if 'ipset' in rule %} |
| 14 | + <source ipset="{{ rule.ipset.name }}" /> |
| 15 | + {%- endif %} |
| 16 | + {%- if 'source' in rule %} |
| 17 | + <source address="{{ rule.source.address }}" {%- if 'invert' in rule.source %}invert="{{ rule.source.invert }}"{%- endif %} /> |
| 18 | + {%- endif %} |
| 19 | + {%- if 'destination' in rule %} |
| 20 | + <destination address="{{ rule.destination.address }}" {%- if 'invert' in rule.destination %}invert="{{ rule.destination.invert }}"{%- endif %} /> |
| 21 | + {%- endif %} |
| 22 | + {%- if 'service' in rule %} |
| 23 | + <service name="{{ rule.service }}" /> |
| 24 | + {%- endif %} |
| 25 | + {%- if 'port' in rule %} |
| 26 | + <port port="{{ rule.port.portid }}" protocol="{{ rule.port.protocol }}" /> |
| 27 | + {%- endif %} |
| 28 | + {%- if 'protocol' in rule %} |
| 29 | + <protocol value="{{ rule.protocol }}" /> |
| 30 | + {%- endif %} |
| 31 | + {%- if 'icmp_block' in rule %} |
| 32 | + <icmp-block name="{{ rule.icmp_block }}" /> |
| 33 | + {%- endif %} |
| 34 | + {%- if 'icmp_type' in rule %} |
| 35 | + <icmp-type name="{{ rule.icmp_type }}" /> |
| 36 | + {%- endif %} |
| 37 | + {%- if 'masquerade' in rule %} |
| 38 | + {%- if rule.masquerade %}<masquerade/>{%- endif %} |
| 39 | + {%- endif %} |
| 40 | + {%- if 'forward_port' in rule %} |
| 41 | + {%- if 'comment' in rule.forward_port %} |
| 42 | + <!-- {{ rule.forward_port.comment }} --> |
| 43 | + {%- endif %} |
| 44 | + <forward-port port="{{ rule.forward_port.portid }}" protocol="{{ rule.forward_port.protocol }}"{%- if 'to_port' in rule.forward_port %} to-port="{{ rule.forward_port.to_port }}"{%- endif %}{%- if 'to_addr' in rule.forward_port %} to-addr="{{ rule.forward_port.to_addr }}"{%- endif %} /> |
| 45 | + {%- endif %} |
| 46 | + {%- if 'source_port' in rule %} |
| 47 | + {%- if 'comment' in rule.source_port %} |
| 48 | + <!-- {{ rule.source_port.comment }} --> |
| 49 | + {%- endif %} |
| 50 | + <source-port port="{{ rule.source_port.portid }}" protocol="{{ rule.source_port.protocol }}"{%- if 'to_port' in rule.source_port %} to-port="{{ rule.source_port.to_port }}"{%- endif %}{%- if 'to_addr' in rule.source_port %} to-addr="{{ rule.source_port.to_addr }}"{%- endif %} /> |
| 51 | + {%- endif %} |
| 52 | + {%- if 'log' in rule %} |
| 53 | + <log{%- if 'prefix' in rule.log %} prefix="{{ rule.log.prefix }}"{%- endif %}{%- if 'level' in rule.log %} level="{{ rule.log.level }}"{%- endif %}> |
| 54 | + {%- if 'limit' in rule.log %} |
| 55 | + <limit value="{{ rule.log.limit }}"/> |
| 56 | + {%- endif %} |
| 57 | + </log> |
| 58 | + {%- endif %} |
| 59 | + {%- if 'audit' in rule %} |
| 60 | + <audit>{%- if 'limit' in rule.audit %} <limit value="{{ rule.audit.limit }}"/>{%- endif %}</audit> |
| 61 | + {%- endif %} |
| 62 | + {%- if 'accept' in rule %} |
| 63 | + <accept/> |
| 64 | + {%- endif %} |
| 65 | + {%- if 'reject' in rule %} |
| 66 | + <reject{%- if 'type' in rule.reject %} type="{{ rule.reject.type }}"{%- endif %} /> |
| 67 | + {%- endif %} |
| 68 | + {%- if 'drop' in rule %} |
| 69 | + <drop/> |
| 70 | + {%- endif %} |
| 71 | + </rule> |
| 72 | +{%- endmacro %} |
7 | 73 | <zone{%- if 'target' in zone %} target="{{ zone.target }}"{%- endif %}>
|
8 | 74 | {% if 'short' in zone %}<short>{{ zone.short }}</short>{% else %}<short>{{ name }}</short>{% endif %}
|
9 | 75 | {% if 'description' in zone %}<description>{{ zone.description }}</description>{% endif %}
|
|
82 | 148 | <source-port port="{{ v.port }}" protocol="{{ v.protocol }}" />
|
83 | 149 | {%- endfor %}
|
84 | 150 | {%- endif %}
|
85 |
| - |
86 | 151 | {%- if 'rich_rules' in zone %}
|
87 |
| - {%- for rule in zone.rich_rules %} |
88 |
| - {%- if 'family' in rule %} |
89 |
| - <rule family="{{ rule.family }}"> |
| 152 | + {%- if zone.rich_rules is list %} |
| 153 | + {%- set rich_rules = zone.rich_rules %} |
90 | 154 | {%- else %}
|
91 |
| - <rule> |
92 |
| - {%- endif %} |
93 |
| - {%- if 'ipset' in rule %} |
94 |
| - <source ipset="{{ rule.ipset.name }}" /> |
95 |
| - {%- endif %} |
96 |
| - {%- if 'source' in rule %} |
97 |
| - <source address="{{ rule.source.address }}" {%- if 'invert' in rule.source %}invert="{{ rule.source.invert }}"{%- endif %} /> |
98 |
| - {%- endif %} |
99 |
| - {%- if 'destination' in rule %} |
100 |
| - <destination address="{{ rule.destination.address }}" {%- if 'invert' in rule.destination %}invert="{{ rule.destination.invert }}"{%- endif %} /> |
101 |
| - {%- endif %} |
102 |
| - {%- if 'service' in rule %} |
103 |
| - <service name="{{ rule.service }}" /> |
104 |
| - {%- endif %} |
105 |
| - {%- if 'port' in rule %} |
106 |
| - <port port="{{ rule.port.portid }}" protocol="{{ rule.port.protocol }}" /> |
107 |
| - {%- endif %} |
108 |
| - {%- if 'protocol' in rule %} |
109 |
| - <protocol value="{{ rule.protocol }}" /> |
110 |
| - {%- endif %} |
111 |
| - {%- if 'icmp_block' in rule %} |
112 |
| - <icmp-block name="{{ rule.icmp_block }}" /> |
113 |
| - {%- endif %} |
114 |
| - {%- if 'icmp_type' in rule %} |
115 |
| - <icmp-type name="{{ rule.icmp_type }}" /> |
116 |
| - {%- endif %} |
117 |
| - {%- if 'masquerade' in rule %} |
118 |
| - {%- if rule.masquerade %}<masquerade/>{%- endif %} |
119 |
| - {%- endif %} |
120 |
| - {%- if 'forward_port' in rule %} |
121 |
| - {%- if 'comment' in rule.forward_port %} |
122 |
| - <!-- {{ rule.forward_port.comment }} --> |
123 |
| - {%- endif %} |
124 |
| - <forward-port port="{{ rule.forward_port.portid }}" protocol="{{ rule.forward_port.protocol }}"{%- if 'to_port' in rule.forward_port %} to-port="{{ rule.forward_port.to_port }}"{%- endif %}{%- if 'to_addr' in rule.forward_port %} to-addr="{{ rule.forward_port.to_addr }}"{%- endif %} /> |
125 |
| - {%- endif %} |
126 |
| - {%- if 'source_port' in rule %} |
127 |
| - {%- if 'comment' in rule.source_port %} |
128 |
| - <!-- {{ rule.source_port.comment }} --> |
129 |
| - {%- endif %} |
130 |
| - <source-port port="{{ rule.source_port.portid }}" protocol="{{ rule.source_port.protocol }}"{%- if 'to_port' in rule.source_port %} to-port="{{ rule.source_port.to_port }}"{%- endif %}{%- if 'to_addr' in rule.source_port %} to-addr="{{ rule.source_port.to_addr }}"{%- endif %} /> |
131 |
| - {%- endif %} |
132 |
| - {%- if 'log' in rule %} |
133 |
| - <log{%- if 'prefix' in rule.log %} prefix="{{ rule.log.prefix }}"{%- endif %}{%- if 'level' in rule.log %} level="{{ rule.log.level }}"{%- endif %}> |
134 |
| - {%- if 'limit' in rule.log %} |
135 |
| - <limit value="{{ rule.log.limit }}"/> |
136 |
| - {%- endif %} |
137 |
| - </log> |
138 |
| - {%- endif %} |
139 |
| - {%- if 'audit' in rule %} |
140 |
| - <audit>{%- if 'limit' in rule.audit %} <limit value="{{ rule.audit.limit }}"/>{%- endif %}</audit> |
141 |
| - {%- endif %} |
142 |
| - {%- if 'accept' in rule %} |
143 |
| - <accept/> |
| 155 | + {%- set expanded_ipset_rules = [] %} |
| 156 | + {%- for name,rule in zone.rich_rules|dictsort %} |
| 157 | + {%- if 'ipsets' in rule %} |
| 158 | + {%- for ipset in rule.ipsets %} |
| 159 | + {%- set tmp_rule = {} %} |
| 160 | + {%- set _dummy = tmp_rule.update(rule) %} |
| 161 | + {%- set _dummy = tmp_rule.update({'ipset':{'name':ipset}}) %} |
| 162 | + {%- set _dummy = expanded_ipset_rules.append(tmp_rule) %} |
| 163 | + {%- endfor %} |
| 164 | + {%- else %} |
| 165 | + {%- set _dummy = expanded_ipset_rules.append(rule) %} |
| 166 | + {%- endif %} |
| 167 | + {%- endfor %} |
| 168 | + {%- set rich_rules = [] %} |
| 169 | + {%- for rule in expanded_ipset_rules %} |
| 170 | + {%- if 'services' in rule %} |
| 171 | + {%- for service in rule.services %} |
| 172 | + {%- set tmp_rule = {} %} |
| 173 | + {%- set _dummy = tmp_rule.update(rule) %} |
| 174 | + {%- set _dummy = tmp_rule.update({'service':service}) %} |
| 175 | + {%- set _dummy = rich_rules.append(tmp_rule) %} |
| 176 | + {%- endfor %} |
| 177 | + {%- else %} |
| 178 | + {%- set _dummy = rich_rules.append(rule) %} |
| 179 | + {%- endif %} |
| 180 | + {%- endfor %} |
144 | 181 | {%- endif %}
|
145 |
| - {%- if 'reject' in rule %} |
146 |
| - <reject{%- if 'type' in rule.reject %} type="{{ rule.reject.type }}"{%- endif %} /> |
147 |
| - {%- endif %} |
148 |
| - {%- if 'drop' in rule %} |
149 |
| - <drop/> |
150 |
| - {%- endif %} |
151 |
| - </rule> |
| 182 | + {%- for rule in rich_rules %} |
| 183 | +{{- rich_rule(rule) }} |
152 | 184 | {%- endfor %}
|
153 | 185 | {%- endif %}
|
154 | 186 | </zone>
|
0 commit comments