Skip to content

Commit

Permalink
Merge pull request #189 from tskirvin/master
Browse files Browse the repository at this point in the history
nftables::simplerule::dport - takes port ranges as part of the array
  • Loading branch information
bastelfreak authored Nov 23, 2023
2 parents a7cb680 + 825f4eb commit b563353
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2377,7 +2377,7 @@ Alias of `Pattern[/^@[-a-zA-Z0-9_]+$/]`

Represents a port expression to be used within a rule.

Alias of `Variant[Array[Stdlib::Port, 1], Stdlib::Port, Nftables::Port::Range]`
Alias of `Variant[Array[Variant[Nftables::Port::Range, Stdlib::Port], 1], Stdlib::Port, Nftables::Port::Range]`

### <a name="Nftables--Port--Range"></a>`Nftables::Port::Range`

Expand Down
18 changes: 18 additions & 0 deletions spec/defines/simplerule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,24 @@
}
end

describe 'port array and range' do
let(:params) do
{
dport: [333, 335, '338-339'],
sport: [433, 435, '438-439'],
proto: 'tcp',
}
end

it { is_expected.to compile }

it {
expect(subject).to contain_nftables__rule('default_in-my_default_rule_name').with(
content: 'tcp sport {433, 435, 438-439} tcp dport {333, 335, 338-339} accept'
)
}
end

describe 'only sport TCP traffic' do
let(:params) do
{
Expand Down
1 change: 1 addition & 0 deletions spec/type_aliases/nftables_port_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
describe 'Nftables::Port' do
it { is_expected.to allow_value(53) }
it { is_expected.to allow_value([1, 1985, 65_535]) }
it { is_expected.to allow_value([1, '53-55']) }
it { is_expected.to allow_value('53-55') }
it { is_expected.not_to allow_value('53') }
it { is_expected.not_to allow_value([]) }
Expand Down
2 changes: 1 addition & 1 deletion types/port.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# @summary
# Represents a port expression to be used within a rule.
type Nftables::Port = Variant[
Array[Stdlib::Port, 1],
Array[Variant[Nftables::Port::Range, Stdlib::Port], 1],
Stdlib::Port,
Nftables::Port::Range,
]

0 comments on commit b563353

Please sign in to comment.