Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nftables::simplerule::dport - takes port ranges as part of the array #189

Merged
merged 6 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2278,7 +2278,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],
traylenator marked this conversation as resolved.
Show resolved Hide resolved
Stdlib::Port,
Nftables::Port::Range,
]
Loading