Skip to content

Commit

Permalink
Allow a singular numeric port for the --to-ports parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
gcoxmoz committed Mar 27, 2024
1 parent 6620ad2 commit bc93563
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/puppet/type/firewall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,7 @@
DESC
},
toports: {
type: 'Optional[Pattern[/^\d+(?:-\d+)?$/]]',
type: 'Optional[Variant[Integer[0, 65535], Pattern[/^\d+(?:-\d+)?$/]]]',
desc: <<-DESC
For REDIRECT/MASQUERADE this is the port that will replace the destination/source port.
Can specify a single new port or an inclusive range of ports.
Expand Down
11 changes: 11 additions & 0 deletions spec/acceptance/firewall_attributes_happy_path_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ class { '::firewall': }
jump => 'REDIRECT',
toports => '2222',
}
firewall { '575 - toports-numeric':
proto => icmp,
table => 'nat',
chain => 'PREROUTING',
jump => 'REDIRECT',
toports => 3333,
}
firewall { '581 - pkttype':
ensure => present,
proto => tcp,
Expand Down Expand Up @@ -441,6 +448,10 @@ class { '::firewall': }
expect(result.stdout).to match(%r{-A PREROUTING -p (icmp|1) -m comment --comment "574 - toports" -j REDIRECT --to-ports 2222})
end

it 'toports-numeric is set' do
expect(result.stdout).to match(%r{-A PREROUTING -p (icmp|1) -m comment --comment "575 - toports-numeric" -j REDIRECT --to-ports 3333})
end

it 'rpfilter is set' do
expect(result.stdout).to match(%r{-A PREROUTING -p (tcp|6) -m rpfilter --loose --validmark --accept-local --invert -m comment --comment "900 - set rpfilter" -j ACCEPT})
end
Expand Down
6 changes: 3 additions & 3 deletions spec/unit/puppet/type/firewall_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -507,9 +507,9 @@
{ name: '001 test rule', tosource: 313 }]
},
':toports': {
valid: [{ name: '001 test rule', toports: '40' }, { name: '001 test rule', tosource: '50-60' }],
invalid: [{ name: '001 test rule', toports: 'invalid' }, { name: '001 test rule', toports: false },
{ name: '001 test rule', toports: 313 }]
valid: [{ name: '001 test rule', toports: '40' }, { name: '001 test rule', tosource: '50-60' },
{ name: '001 test rule', toports: 313 }],
invalid: [{ name: '001 test rule', toports: 'invalid' }, { name: '001 test rule', toports: false }]
},
':to': {
valid: [{ name: '001 test rule', to: '10.0.0.2' }, { name: '001 test rule', to: '10.0.0.2/24' }],
Expand Down

0 comments on commit bc93563

Please sign in to comment.