root / manifests / rules / snat4.pp @ 09cba182
Historique | Voir | Annoter | Télécharger (1,11 ko)
1 |
# @summary manage a ipv4 snat rule |
---|---|
2 |
define nftables::rules::snat4 ( |
3 |
# lint:ignore:parameter_documentation |
4 |
String[1] $snat, |
5 |
Pattern[/^[a-zA-Z0-9_]+$/] $rulename = $title, |
6 |
Pattern[/^\d\d$/] $order = '70', |
7 |
String[1] $chain = 'POSTROUTING', |
8 |
Optional[String[1]] $oif = undef, |
9 |
Optional[String[1]] $saddr = undef, |
10 |
Optional[Enum['tcp','udp']] $proto = undef, |
11 |
Optional[Variant[String,Stdlib::Port]] $dport = undef, |
12 |
Enum['present','absent'] $ensure = 'present', |
13 |
# lint:endignore |
14 |
) { |
15 |
$oifname = $oif ? { |
16 |
undef => '', |
17 |
default => "oifname ${oif} ", |
18 |
} |
19 |
$src = $saddr ? { |
20 |
undef => '', |
21 |
default => "ip saddr ${saddr} ", |
22 |
} |
23 |
|
24 |
if $proto and $dport { |
25 |
$protocol = '' |
26 |
$port = "${proto} dport ${dport} " |
27 |
} elsif $proto { |
28 |
$protocol = "${proto} " |
29 |
$port = '' |
30 |
} elsif $dport { |
31 |
$protocol = '' |
32 |
$port = "tcp dport ${dport} " |
33 |
} else { |
34 |
$protocol = '' |
35 |
$port = '' |
36 |
} |
37 |
|
38 |
nftables::rule { |
39 |
"${chain}-${rulename}": |
40 |
ensure => $ensure, |
41 |
table => 'ip-nat', |
42 |
order => $order, |
43 |
content => "${oifname}${src}${protocol}${port}snat ${snat}"; |
44 |
} |
45 |
} |