root / manifests / rules / dnat4.pp @ ffc8b86f
Historique | Voir | Annoter | Télécharger (1,1 ko)
1 |
# manage a ipv4 dnat rule |
---|---|
2 |
define nftables::rules::dnat4 ( |
3 |
# lint:ignore:parameter_documentation |
4 |
Pattern[/^[12]?\d{1,2}\.[12]?\d{1,2}\.[12]?\d{1,2}\.[12]?\d{1,2}$/] $daddr, |
5 |
Variant[String,Stdlib::Port] $port, |
6 |
Pattern[/^[a-zA-Z0-9_]+$/] $rulename = $title, |
7 |
Pattern[/^\d\d$/] $order = '50', |
8 |
String[1] $chain = 'default_fwd', |
9 |
Optional[String[1]] $iif = undef, |
10 |
Enum['tcp','udp'] $proto = 'tcp', |
11 |
Optional[Variant[String,Stdlib::Port]] $dport = undef, |
12 |
Enum['present','absent'] $ensure = 'present', |
13 |
# lint:endignore |
14 |
) { |
15 |
$iifname = $iif ? { |
16 |
undef => '', |
17 |
default => "iifname ${iif} ", |
18 |
} |
19 |
$filter_port = $dport ? { |
20 |
undef => $port, |
21 |
default => $dport, |
22 |
} |
23 |
$nat_port = $dport ? { |
24 |
undef => '', |
25 |
default => ":${dport}", |
26 |
} |
27 |
|
28 |
nftables::rule { |
29 |
default: |
30 |
ensure => $ensure, |
31 |
order => $order; |
32 |
"${chain}-${rulename}": |
33 |
content => "${iifname}ip daddr ${daddr} ${proto} dport ${filter_port} accept"; |
34 |
"PREROUTING-${rulename}": |
35 |
table => "ip-${nftables::nat_table_name}", |
36 |
content => "${iifname}${proto} dport ${port} dnat to ${daddr}${nat_port}"; |
37 |
} |
38 |
} |