Skip to content

Commit cc93565

Browse files
author
Morgan Haskel
committed
MODULES-1612 - sync socket
1 parent e422c18 commit cc93565

3 files changed

Lines changed: 72 additions & 6 deletions

File tree

README.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ This type enables you to manage firewall rules within Puppet.
339339

340340
* `ip6tables`: Ip6tables type provider
341341
* Required binaries: `ip6tables-save`, `ip6tables`.
342-
* Supported features: `connection_limiting`, `dnat`, `hop_limiting`, `icmp_match`, `interface_match`, `iptables`, `isfirstfrag`, `ishasmorefrags`, `islastfrag`, `log_level`, `log_prefix`, `mark`, `owner`, `pkttype`, `rate_limiting`, `recent_limiting`, `reject_type`, `snat`, `state_match`, `tcp_flags`.
342+
* Supported features: `connection_limiting`, `dnat`, `hop_limiting`, `icmp_match`, `interface_match`, `iptables`, `isfirstfrag`, `ishasmorefrags`, `islastfrag`, `log_level`, `log_prefix`, `mark`, `owner`, `pkttype`, `rate_limiting`, `recent_limiting`, `reject_type`, `snat`, `socket`, `state_match`, `tcp_flags`.
343343

344344
* `iptables`: Iptables type provider
345345
* Required binaries: `iptables-save`, `iptables`.

lib/puppet/provider/firewall/ip6tables.rb

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
has_feature :ishasmorefrags
2222
has_feature :islastfrag
2323
has_feature :isfirstfrag
24+
has_feature :socket
2425
has_feature :address_type
2526
has_feature :iprange
2627

@@ -85,6 +86,7 @@ def self.iptables_save(*args)
8586
:rseconds => "--seconds",
8687
:rsource => "--rsource",
8788
:rttl => "--rttl",
89+
:socket => "-m socket",
8890
:source => "-s",
8991
:sport => ["-m multiport --sports", "--sport"],
9092
:src_range => '-m iprange --src-range',
@@ -104,7 +106,16 @@ def self.iptables_save(*args)
104106

105107
# These are known booleans that do not take a value, but we want to munge
106108
# to true if they exist.
107-
@known_booleans = [:ishasmorefrags, :islastfrag, :isfirstfrag, :rsource, :rdest, :reap, :rttl]
109+
@known_booleans = [
110+
:ishasmorefrags,
111+
:islastfrag,
112+
:isfirstfrag,
113+
:rsource,
114+
:rdest,
115+
:reap,
116+
:rttl,
117+
:socket
118+
]
108119

109120
# Create property methods dynamically
110121
(@resource_map.keys << :chain << :table << :action).each do |property|
@@ -143,9 +154,9 @@ def self.iptables_save(*args)
143154
@resource_list = [:table, :source, :destination, :iniface, :outiface,
144155
:proto, :ishasmorefrags, :islastfrag, :isfirstfrag, :src_range, :dst_range,
145156
:tcp_flags, :gid, :uid, :mac_source, :sport, :dport, :port, :dst_type,
146-
:src_type, :pkttype, :name, :state, :ctstate, :icmp, :hop_limit, :limit,
147-
:burst, :recent, :rseconds, :reap, :rhitcount, :rttl, :rname, :rsource,
148-
:rdest, :jump, :todest, :tosource, :toports, :log_level, :log_prefix,
149-
:reject, :connlimit_above, :connlimit_mask, :connmark]
157+
:src_type, :socket, :pkttype, :name, :state, :ctstate, :icmp, :hop_limit,
158+
:limit, :burst, :recent, :rseconds, :reap, :rhitcount, :rttl, :rname,
159+
:rsource, :rdest, :jump, :todest, :tosource, :toports, :log_level,
160+
:log_prefix, :reject, :connlimit_above, :connlimit_mask, :connmark]
150161

151162
end

spec/acceptance/firewall_spec.rb

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,6 +1250,61 @@ class { '::firewall': }
12501250
end
12511251
end
12521252

1253+
# ip6tables has limited `-m socket` support
1254+
if default['platform'] !~ /el-5/ and default['platform'] !~ /ubuntu-1004/ and default['platform'] !~ /debian-6/ and default['platform'] !~ /sles/
1255+
describe 'socket' do
1256+
context 'true' do
1257+
it 'applies' do
1258+
pp = <<-EOS
1259+
class { '::firewall': }
1260+
firewall { '605 - test':
1261+
ensure => present,
1262+
proto => tcp,
1263+
port => '605',
1264+
action => accept,
1265+
chain => 'INPUT',
1266+
socket => true,
1267+
provider => 'ip6tables',
1268+
}
1269+
EOS
1270+
1271+
apply_manifest(pp, :catch_failures => true)
1272+
end
1273+
1274+
it 'should contain the rule' do
1275+
shell('ip6tables-save') do |r|
1276+
expect(r.stdout).to match(/-A INPUT -p tcp -m multiport --ports 605 -m socket -m comment --comment "605 - test" -j ACCEPT/)
1277+
end
1278+
end
1279+
end
1280+
1281+
context 'false' do
1282+
it 'applies' do
1283+
pp = <<-EOS
1284+
class { '::firewall': }
1285+
firewall { '606 - test':
1286+
ensure => present,
1287+
proto => tcp,
1288+
port => '606',
1289+
action => accept,
1290+
chain => 'INPUT',
1291+
socket => false,
1292+
provider => 'ip6tables',
1293+
}
1294+
EOS
1295+
1296+
apply_manifest(pp, :catch_failures => true)
1297+
end
1298+
1299+
it 'should contain the rule' do
1300+
shell('ip6tables-save') do |r|
1301+
expect(r.stdout).to match(/-A INPUT -p tcp -m multiport --ports 606 -m comment --comment "606 - test" -j ACCEPT/)
1302+
end
1303+
end
1304+
end
1305+
end
1306+
end
1307+
12531308
# ip6tables only support addrtype on a limited set of platforms
12541309
if default['platform'] =~ /el-7/ or default['platform'] =~ /debian-7/ or default['platform'] =~ /ubuntu-1404/
12551310
['dst_type', 'src_type'].each do |type|

0 commit comments

Comments
 (0)