Révision 3a469f2b
Implement nftables::simplerule::saddr
manifests/simplerule.pp | ||
---|---|---|
47 | 47 |
# @param sport |
48 | 48 |
# The source port, ports or port range. |
49 | 49 |
# |
50 |
# @param saddr |
|
51 |
# The source address, CIDR or set to match. |
|
52 |
# |
|
50 | 53 |
# @param counter |
51 | 54 |
# Enable traffic counters for the matched traffic. |
52 | 55 |
|
... | ... | |
63 | 66 |
Optional[Variant[Stdlib::IP::Address::V6, Stdlib::IP::Address::V4, Pattern[/^@[-a-zA-Z0-9_]+$/]]] $daddr = undef, |
64 | 67 |
Enum['ip', 'ip6'] $set_type = 'ip6', |
65 | 68 |
Optional[Variant[Array[Stdlib::Port, 1], Stdlib::Port, Pattern[/\d+-\d+/]]] $sport = undef, |
69 |
Optional[Variant[Stdlib::IP::Address::V6, Stdlib::IP::Address::V4, Pattern[/^@[-a-zA-Z0-9_]+$/]]] $saddr = undef, |
|
66 | 70 |
Boolean $counter = false, |
67 | 71 |
) { |
68 | 72 |
if $dport and !$proto { |
... | ... | |
84 | 88 |
'proto' => $proto, |
85 | 89 |
'daddr' => $daddr, |
86 | 90 |
'set_type' => $set_type, |
91 |
'saddr' => $saddr, |
|
87 | 92 |
'sport' => $sport, |
88 | 93 |
} |
89 | 94 |
), |
spec/defines/simplerule_spec.rb | ||
---|---|---|
51 | 51 |
proto: 'udp', |
52 | 52 |
chain: 'default_out', |
53 | 53 |
daddr: '2001:1458::/32', |
54 |
saddr: '2001:145c::/32', |
|
54 | 55 |
} |
55 | 56 |
end |
56 | 57 |
|
57 | 58 |
it { is_expected.to compile } |
58 | 59 |
it { |
59 | 60 |
is_expected.to contain_nftables__rule('default_out-my_big_rule').with( |
60 |
content: 'udp sport {444} udp dport {333} ip6 daddr 2001:1458::/32 counter accept comment "this is my rule"', |
|
61 |
content: 'udp sport {444} udp dport {333} ip6 saddr 2001:145c::/32 ip6 daddr 2001:1458::/32 counter accept comment "this is my rule"',
|
|
61 | 62 |
order: '50', |
62 | 63 |
) |
63 | 64 |
} |
... | ... | |
177 | 178 |
} |
178 | 179 |
end |
179 | 180 |
|
181 |
describe 'with an IPv6 address as saddr' do |
|
182 |
let(:params) do |
|
183 |
{ |
|
184 |
saddr: '2001:1458:0000:0000:0000:0000:0000:0003', |
|
185 |
} |
|
186 |
end |
|
187 |
|
|
188 |
it { is_expected.to compile } |
|
189 |
it { |
|
190 |
is_expected.to contain_nftables__rule('default_in-my_default_rule_name').with( |
|
191 |
content: 'ip6 saddr 2001:1458:0000:0000:0000:0000:0000:0003 accept', |
|
192 |
) |
|
193 |
} |
|
194 |
end |
|
195 |
|
|
180 | 196 |
describe 'with an IPv6 set as daddr, default set_type' do |
181 | 197 |
let(:params) do |
182 | 198 |
{ |
... | ... | |
208 | 224 |
} |
209 | 225 |
end |
210 | 226 |
|
227 |
describe 'with a IPv6 set as saddr' do |
|
228 |
let(:params) do |
|
229 |
{ |
|
230 |
saddr: '@my6_set', |
|
231 |
set_type: 'ip6', |
|
232 |
} |
|
233 |
end |
|
234 |
|
|
235 |
it { is_expected.to compile } |
|
236 |
it { |
|
237 |
is_expected.to contain_nftables__rule('default_in-my_default_rule_name').with( |
|
238 |
content: 'ip6 saddr @my6_set accept', |
|
239 |
) |
|
240 |
} |
|
241 |
end |
|
242 |
|
|
211 | 243 |
describe 'with counter enabled' do |
212 | 244 |
let(:params) do |
213 | 245 |
{ |
templates/simplerule.epp | ||
---|---|---|
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 | 7 |
Optional[Variant[Array[Stdlib::Port, 1], Stdlib::Port, String]] $sport, |
8 |
Optional[Variant[Stdlib::IP::Address::V6, Stdlib::IP::Address::V4, Pattern[/^@[-a-zA-Z0-9_]+$/]]] $saddr, |
|
8 | 9 |
Boolean $counter, |
9 | 10 |
| -%> |
10 | 11 |
<%- if $proto { |
... | ... | |
34 | 35 |
} else { |
35 | 36 |
$_dst_hosts = undef |
36 | 37 |
} -%> |
38 |
<%- if $saddr { |
|
39 |
if $saddr =~ Stdlib::IP::Address::V6 { |
|
40 |
$_src_hosts = "ip6 saddr ${saddr}" |
|
41 |
} elsif $daddr =~ Stdlib::IP::Address::V4 { |
|
42 |
$_src_hosts = "ip saddr ${saddr}" |
|
43 |
} else { |
|
44 |
$_src_hosts = $set_type ? { |
|
45 |
'ip' => "ip saddr ${saddr}", |
|
46 |
'ip6' => "ip6 saddr ${saddr}", |
|
47 |
} |
|
48 |
} |
|
49 |
} else { |
|
50 |
$_src_hosts = undef |
|
51 |
} -%> |
|
37 | 52 |
<%- if $proto and $dport { |
38 | 53 |
$_dst_port = "${_proto} dport {${Array($dport, true).join(', ')}}" |
39 | 54 |
} else { |
... | ... | |
54 | 69 |
} else { |
55 | 70 |
$_counter = undef |
56 | 71 |
} -%> |
57 |
<%= regsubst(strip([$_ip_version_filter, $_src_port, $_dst_port, $_dst_hosts, $_counter, $action, $_comment].join(' ')), '\s+', ' ', 'G') -%> |
|
72 |
<%= regsubst(strip([$_ip_version_filter, $_src_port, $_dst_port, $_src_hosts, $_dst_hosts, $_counter, $action, $_comment].join(' ')), '\s+', ' ', 'G') -%> |
Formats disponibles : Unified diff