@@ -30,6 +30,10 @@ class Puppet::Provider::Firewallchain::Firewallchain
3030 $chain_delete_command = '-X'
3131 # Command to set chain policy, works on inbuilt chains only
3232 $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'
3337 # Check if the given chain name references a built in one
3438 $built_in_regex = %r{^(?:INPUT|OUTPUT|FORWARD|PREROUTING|POSTROUTING)$}
3539
@@ -94,7 +98,12 @@ def set(context, changes)
9498
9599 def create ( context , name , should )
96100 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
98107 PuppetX ::Firewall ::Utility . persist_iptables ( context , name , should [ :protocol ] )
99108 end
100109
@@ -150,10 +159,7 @@ def self.process_input(is, should)
150159 should [ :name ] = should [ :title ] if should [ :name ] . nil?
151160 should [ :chain ] , should [ :table ] , should [ :protocol ] = should [ :name ] . split ( ':' )
152161
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
157163 is [ :policy ] = 'accept' if $built_in_regex. match ( is [ :chain ] ) && is [ :policy ] . nil?
158164 # For the same reason assign it the default policy as an intended state if it does not have one
159165 should [ :policy ] = 'accept' if $built_in_regex. match ( should [ :chain ] ) && should [ :policy ] . nil?
0 commit comments