Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit 15aa483

Browse files
committed
Merge pull request #54 from rtkwlf/chain_condition_nil
:none direction value
2 parents 636d7b2 + 79e0201 commit 15aa483

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,22 @@ specified to make the jump conditional. For example:
143143
The rules specified under the `rule` attribute will only be evaluate for packets for which
144144
the rule in `chain_condition` holds.
145145

146+
Sometimes we might want to define a chain where we only want to jump from another chain we define.
147+
By default, an automatic jump will be made to chains defined using the `simple_iptables_rule` resource
148+
from the chain specified using the `direction` attribute of the resource. To prevent jumping to the
149+
chain from the direction chains, we can set the direction attribute to the symbol `:none`.
150+
For example, consider a chain used to log
151+
152+
simple_iptables_rule "logging_drop" do
153+
direction :none
154+
rule ['-j LOG --log-level 4 --log-prefix "IPTABLES_DROP: "',
155+
'-j DROP']
156+
jump false
157+
end
158+
159+
We can then jump to this chain from other simple_iptables_rule chains, but an automatic jump to
160+
this chain won't be added.
161+
146162

147163
`simple_iptables_policy` Resource
148164
---------------------------------
@@ -338,6 +354,10 @@ Which results in the following iptables configuration:
338354

339355
Changes
340356
=======
357+
* 0.6.6 (Aug 1, 2014)
358+
* Added `:none` to one of the values that the attribute `direction` can be set to.
359+
When set to :none, a rule to jump to the chain created will not be added to any
360+
direction chains.
341361
* 0.6.5 (July 20, 2014)
342362
* Fix one-shot testing code to work with Chef versions prior to 11.12.
343363
* Make one-shot testing error line detection code more robust (#48 - Kim Tore Jensen)

providers/rule.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
if not node["simple_iptables"]["chains"][new_resource.table].include?(new_resource.chain)
1212
node.set["simple_iptables"]["chains"][new_resource.table] = node["simple_iptables"]["chains"][new_resource.table].dup << new_resource.chain unless ["PREROUTING", "INPUT", "FORWARD", "OUTPUT", "POSTROUTING"].include?(new_resource.chain)
13-
unless new_resource.chain == new_resource.direction
13+
unless new_resource.chain == new_resource.direction || new_resource.direction == :none
1414
node.set["simple_iptables"]["rules"][new_resource.table] << {:rule => "-A #{new_resource.direction} #{new_resource.chain_condition} --jump #{new_resource.chain}", :weight => new_resource.weight}
1515
end
1616
end

resources/rule.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
attribute :table, :equal_to => ["filter", "nat", "mangle", "raw"], :default => "filter"
55
attribute :rule, :kind_of => [String, Array], :required => true
66
attribute :jump, :kind_of => [String, FalseClass], :default => "ACCEPT"
7-
attribute :direction, :equal_to => ["INPUT", "FORWARD", "OUTPUT", "PREROUTING", "POSTROUTING"], :default => "INPUT"
7+
attribute :direction, :equal_to => ["INPUT", "FORWARD", "OUTPUT", "PREROUTING", "POSTROUTING", :none], :default => "INPUT"
88
attribute :chain_condition, :kind_of => [String]
99
attribute :weight, :kind_of => Integer, :default => 50
1010

0 commit comments

Comments
 (0)