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

Commit b09d6d9

Browse files
committed
Merge pull request #18 from rtkmhart/mangle
Added support for mangle table and fix for chef fail in cases where _chef_lwrp_test chain is left around.
2 parents 82a7852 + b09d31c commit b09d6d9

File tree

7 files changed

+45
-4
lines changed

7 files changed

+45
-4
lines changed

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Additionally, if you want to declare a module (such as log) you can define jump
7070
jump false
7171
end
7272

73-
By default rules are added to the filter table but the nat table is also supported. For example:
73+
By default rules are added to the filter table but the nat and mangle tables are also supported. For example:
7474

7575
# Tomcat redirects
7676
simple_iptables_rule "tomcat" do
@@ -81,6 +81,22 @@ By default rules are added to the filter table but the nat table is also support
8181
jump false
8282
end
8383

84+
#mangle example
85+
#NOTE: set jump to false since iptables expects the -j MARK --set-mark in that order
86+
simple_iptables_rule "mangle" do
87+
table "mangle"
88+
direction "PREROUTING"
89+
jump false
90+
rule "-i eth0 -j MARK --set-mark 0x6
91+
end
92+
93+
#reject all outbound connections attempts to 10/8 on a dual-homed host
94+
simple_iptables_rule "reset_10slash8_outbound" do
95+
direction "OUTPUT"
96+
jump false
97+
rule "-p tcp -o eth0 -d 10/8 --jump REJECT --reject-with tcp-reset"
98+
end
99+
84100
`simple_iptables_policy` Resource
85101
---------------------------------
86102

@@ -229,6 +245,9 @@ Which results in the following iptables configuration:
229245
Changes
230246
=======
231247

248+
* 0.4.0 (May 9, 2013)
249+
* Added support for mangle table (#? - Michael Hart)
250+
* Updated Gemfile to 11.4.4 (#? - Michael Hart)
232251
* 0.3.0 (March 5, 2013)
233252
* Added support for nat table (#10 - Nathan Mische)
234253
* Updated Gemfile for Travis-CI integration (#10 - Nathan Mische)

attributes/default.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
default["simple_iptables"]["rules"]["filter"] = []
22
default["simple_iptables"]["rules"]["nat"] = []
3+
default["simple_iptables"]["rules"]["mangle"] = []
34
default["simple_iptables"]["chains"]["filter"] = []
45
default["simple_iptables"]["chains"]["nat"] = []
6+
default["simple_iptables"]["chains"]["mangle"] = []
57
default["simple_iptables"]["policy"]["filter"] = {}
68
default["simple_iptables"]["policy"]["nat"] = {}
9+
default["simple_iptables"]["policy"]["mangle"] = {}

providers/rule.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
end
3030

3131
def test_rules(new_resource, rules)
32+
#always flush and remove first in case the previous run left it lying around. Ignore any return values.
33+
shell_out("iptables --table #{new_resource.table} --flush _chef_lwrp_test")
34+
shell_out("iptables --table #{new_resource.table} --delete-chain _chef_lwrp_test")
35+
#create the test chain
3236
shell_out!("iptables --table #{new_resource.table} --new-chain _chef_lwrp_test")
3337
begin
3438
rules.each do |rule|

resources/policy.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
actions :set
22

33
attribute :chain, :name_attribute => true, :equal_to => ["INPUT", "FORWARD", "OUTPUT", "PREROUTING", "POSTROUTING"], :default => "INPUT"
4-
attribute :table, :equal_to => ["filter", "nat"], :default => "filter"
4+
attribute :table, :equal_to => ["filter", "nat", "mangle"], :default => "filter"
55
attribute :policy, :equal_to => ["ACCEPT", "DROP"], :required => true
66

77

resources/rule.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
actions :append
22

33
attribute :chain, :name_attribute => true, :kind_of => String
4-
attribute :table, :equal_to => ["filter", "nat"], :default => "filter"
4+
attribute :table, :equal_to => ["filter", "nat", "mangle"], :default => "filter"
55
attribute :rule, :kind_of => [String, Array], :required => true
66
attribute :jump, :kind_of => [String, FalseClass], :default => "ACCEPT"
77
attribute :direction, :equal_to => ["INPUT", "FORWARD", "OUTPUT", "PREROUTING", "POSTROUTING"], :default => "INPUT"

templates/default/iptables-rules.erb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@
1313
COMMIT
1414
# Completed
1515
# This file generated by Chef. Changes will be overwritten.
16+
*mangle
17+
:PREROUTING <%= node["simple_iptables"]["policy"]["mangle"]["PREROUTING"] || "ACCEPT" %> [0:0]<% if Gem::Version.new(/\d+\.\d+.\d+/.match(node["kernel"]["release"])[0]) > Gem::Version.new("2.6.35") -%>
18+
:INPUT <%= node["simple_iptables"]["policy"]["mangle"]["INPUT"] || "ACCEPT" %> [0:0]<% end -%>
19+
:FORWARD <%= node["simple_iptables"]["policy"]["mangle"]["FORWARD"] || "ACCEPT" %> [0:0]
20+
:OUTPUT <%= node["simple_iptables"]["policy"]["mangle"]["OUTPUT"] || "ACCEPT" %> [0:0]
21+
:POSTROUTING <%= node["simple_iptables"]["policy"]["mangle"]["POSTROUTING"] || "ACCEPT" %> [0:0]
22+
<% node["simple_iptables"]["chains"]["mangle"].each do |chain| -%>
23+
:<%= chain %> - [0:0]
24+
<% end -%>
25+
<% node["simple_iptables"]["rules"]["mangle"].each do |rule| -%>
26+
<%= rule %>
27+
<% end -%>
28+
COMMIT
29+
# Completed
30+
# This file generated by Chef. Changes will be overwritten.
1631
*filter
1732
:INPUT <%= node["simple_iptables"]["policy"]["filter"]["INPUT"] || "ACCEPT" %> [0:0]
1833
:FORWARD <%= node["simple_iptables"]["policy"]["filter"]["FORWARD"] || "ACCEPT" %> [0:0]

test/support/Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
source "https://rubygems.org"
22

3-
gem 'chef', '~> 11.4.0'
3+
gem 'chef', '~> 11.4.4'
44
gem 'foodcritic', :platforms => :ruby_19
55
gem 'rake'

0 commit comments

Comments
 (0)