@@ -30,6 +30,10 @@ class Puppet::Provider::Firewallchain::Firewallchain
30
30
$chain_delete_command = '-X'
31
31
# Command to set chain policy, works on inbuilt chains only
32
32
$chain_policy_command = '-P'
33
+ # Command to list specific table so it will generate necessary output for iptables-save
34
+ # The retrieval of in-built chains may get confused by `iptables-save` tendency to not return table information
35
+ # for tables that have not yet been interacted with.
36
+ $table_list_command = '-L'
33
37
# Check if the given chain name references a built in one
34
38
$built_in_regex = %r{^(?:INPUT|OUTPUT|FORWARD|PREROUTING|POSTROUTING)$}
35
39
@@ -94,7 +98,12 @@ def set(context, changes)
94
98
95
99
def create ( context , name , should )
96
100
context . notice ( "Creating Chain '#{ name } ' with #{ should . inspect } " )
97
- Puppet ::Provider . execute ( [ $base_command[ should [ :protocol ] ] , should [ :table ] , $chain_create_command, should [ :chain ] ] . join ( ' ' ) )
101
+ # If a built-in chain is not present we assume that corresponding table has not been interacted with
102
+ if $built_in_regex. match ( should [ :chain ] )
103
+ Puppet ::Provider . execute ( [ $base_command[ should [ :protocol ] ] , should [ :table ] , $table_list_command] . join ( ' ' ) )
104
+ else
105
+ Puppet ::Provider . execute ( [ $base_command[ should [ :protocol ] ] , should [ :table ] , $chain_create_command, should [ :chain ] ] . join ( ' ' ) )
106
+ end
98
107
PuppetX ::Firewall ::Utility . persist_iptables ( context , name , should [ :protocol ] )
99
108
end
100
109
@@ -150,10 +159,7 @@ def self.process_input(is, should)
150
159
should [ :name ] = should [ :title ] if should [ :name ] . nil?
151
160
should [ :chain ] , should [ :table ] , should [ :protocol ] = should [ :name ] . split ( ':' )
152
161
153
- # If an in-built chain, always treat it as being present and ensure it is assigned a policy
154
- # The retrieval of in-built chains may get confused by `iptables-save` tendency to not return table information
155
- # for tables that have not yet been interacted with.
156
- is [ :ensure ] = 'present' if $built_in_regex. match ( is [ :chain ] )
162
+ # If an in-built chain, ensure it is assigned a policy
157
163
is [ :policy ] = 'accept' if $built_in_regex. match ( is [ :chain ] ) && is [ :policy ] . nil?
158
164
# For the same reason assign it the default policy as an intended state if it does not have one
159
165
should [ :policy ] = 'accept' if $built_in_regex. match ( should [ :chain ] ) && should [ :policy ] . nil?
0 commit comments