Révision d43ced4d
Implement nftables:;simplerule::counter
manifests/simplerule.pp | ||
---|---|---|
24 | 24 |
$daddr = undef, |
25 | 25 |
Enum['ip', 'ip6'] |
26 | 26 |
$set_type = 'ip6', |
27 |
Boolean |
|
28 |
$counter = false, |
|
27 | 29 |
){ |
28 | 30 |
|
29 | 31 |
if $dport and !$proto { |
... | ... | |
36 | 38 |
{ |
37 | 39 |
'action' => $action, |
38 | 40 |
'comment' => $comment, |
41 |
'counter' => $counter, |
|
39 | 42 |
'dport' => $dport, |
40 | 43 |
'proto' => $proto, |
41 | 44 |
'daddr' => $daddr, |
spec/defines/simplerule_spec.rb | ||
---|---|---|
35 | 35 |
{ |
36 | 36 |
action: 'accept', |
37 | 37 |
comment: 'this is my rule', |
38 |
counter: true, |
|
38 | 39 |
dport: 333, |
39 | 40 |
proto: 'udp', |
40 | 41 |
chain: 'default_out', |
... | ... | |
45 | 46 |
it { is_expected.to compile } |
46 | 47 |
it { |
47 | 48 |
is_expected.to contain_nftables__rule('default_out-my_big_rule').with( |
48 |
content: 'udp dport 333 ip6 daddr 2001:1458::/32 accept comment "this is my rule"', |
|
49 |
content: 'udp dport 333 ip6 daddr 2001:1458::/32 counter accept comment "this is my rule"',
|
|
49 | 50 |
order: '50', |
50 | 51 |
) |
51 | 52 |
} |
... | ... | |
178 | 179 |
} |
179 | 180 |
end |
180 | 181 |
|
182 |
describe 'with counter enabled' do |
|
183 |
let(:params) do |
|
184 |
{ |
|
185 |
counter: true, |
|
186 |
} |
|
187 |
end |
|
188 |
|
|
189 |
it { is_expected.to compile } |
|
190 |
it { |
|
191 |
is_expected.to contain_nftables__rule('default_in-my_default_rule_name').with( |
|
192 |
content: 'counter accept', |
|
193 |
) |
|
194 |
} |
|
195 |
end |
|
181 | 196 |
end |
182 | 197 |
end |
183 | 198 |
end |
templates/simplerule.epp | ||
---|---|---|
4 | 4 |
Optional[String] $proto, |
5 | 5 |
Optional[Variant[Stdlib::IP::Address::V6, Stdlib::IP::Address::V4, Pattern[/^@[-a-zA-Z0-9_]+$/]]] $daddr, |
6 | 6 |
Enum['ip', 'ip6'] $set_type, |
7 |
Boolean $counter, |
|
7 | 8 |
| -%> |
8 | 9 |
<%- if $proto { |
9 | 10 |
$_proto = $proto ? { |
... | ... | |
46 | 47 |
} else { |
47 | 48 |
$_comment = undef |
48 | 49 |
} -%> |
49 |
<%= regsubst(strip([$_ip_version_filter, $_dst_port, $_dst_hosts, $action, $_comment].join(' ')), '\s+', ' ', 'G') -%> |
|
50 |
<%- if $counter { |
|
51 |
$_counter = "counter" |
|
52 |
} else { |
|
53 |
$_counter = undef |
|
54 |
} -%> |
|
55 |
<%= regsubst(strip([$_ip_version_filter, $_dst_port, $_dst_hosts, $_counter, $action, $_comment].join(' ')), '\s+', ' ', 'G') -%> |
Formats disponibles : Unified diff