root / manifests / simplerule.pp @ fb58f7b3
Historique | Voir | Annoter | Télécharger (1,59 ko)
1 |
# @summary Provides a simplified interface to nftables::rule for basic use cases |
---|---|
2 |
# |
3 |
# @example allow incoming traffic on port 543 TCP to a given IP range and count packets |
4 |
# nftables::simplerule{'my_service_in': |
5 |
# action => 'accept', |
6 |
# comment => 'allow traffic to port 543', |
7 |
# counter => true, |
8 |
# proto => 'tcp', |
9 |
# dport => 543, |
10 |
# daddr => '2001:1458::/32', |
11 |
# } |
12 |
|
13 |
define nftables::simplerule ( |
14 |
Enum['present','absent'] $ensure = 'present', |
15 |
Pattern[/^[-a-zA-Z0-9_]+$/] $rulename = $title, |
16 |
Pattern[/^\d\d$/] $order = '50', |
17 |
String $chain = 'default_in', |
18 |
String $table = 'inet-filter', |
19 |
Enum['accept', 'drop'] $action = 'accept', |
20 |
Optional[String] $comment = undef, |
21 |
Optional[Variant[Array[Stdlib::Port, 1], Stdlib::Port, Pattern[/\d+-\d+/]]] $dport = undef, |
22 |
Optional[Enum['tcp', 'tcp4', 'tcp6', 'udp', 'udp4', 'udp6']] $proto = undef, |
23 |
Optional[Variant[Stdlib::IP::Address::V6, Stdlib::IP::Address::V4, Pattern[/^@[-a-zA-Z0-9_]+$/]]] $daddr = undef, |
24 |
Enum['ip', 'ip6'] $set_type = 'ip6', |
25 |
Boolean $counter = false, |
26 |
) { |
27 |
if $dport and !$proto { |
28 |
fail('Specifying a transport protocol via $proto is mandatory when passing a $dport') |
29 |
} |
30 |
|
31 |
if $ensure == 'present' { |
32 |
nftables::rule { "${chain}-${rulename}": |
33 |
content => epp('nftables/simplerule.epp', |
34 |
{ |
35 |
'action' => $action, |
36 |
'comment' => $comment, |
37 |
'counter' => $counter, |
38 |
'dport' => $dport, |
39 |
'proto' => $proto, |
40 |
'daddr' => $daddr, |
41 |
'set_type' => $set_type, |
42 |
} |
43 |
), |
44 |
order => $order, |
45 |
table => $table, |
46 |
} |
47 |
} |
48 |
} |