root / manifests / rules / masquerade.pp @ 020842af
Historique | Voir | Annoter | Télécharger (1,24 ko)
1 |
# masquerade all outgoing traffic |
---|---|
2 |
define nftables::rules::masquerade ( |
3 |
# lint:ignore:parameter_documentation |
4 |
Pattern[/^[a-zA-Z0-9_]+$/] $rulename = $title, |
5 |
Pattern[/^\d\d$/] $order = '70', |
6 |
String[1] $chain = 'POSTROUTING', |
7 |
Optional[String[1]] $oif = undef, |
8 |
Optional[String[1]] $saddr = undef, |
9 |
Optional[String[1]] $daddr = 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 |
$dst = $daddr ? { |
24 |
undef => '', |
25 |
default => "ip daddr ${daddr} ", |
26 |
} |
27 |
|
28 |
if $proto and $dport { |
29 |
$protocol = '' |
30 |
$port = "${proto} dport ${dport} " |
31 |
} elsif $proto { |
32 |
$protocol = "${proto} " |
33 |
$port = '' |
34 |
} elsif $dport { |
35 |
$protocol = '' |
36 |
$port = "tcp dport ${dport} " |
37 |
} else { |
38 |
$protocol = '' |
39 |
$port = '' |
40 |
} |
41 |
|
42 |
nftables::rule { |
43 |
"${chain}-${rulename}": |
44 |
ensure => $ensure, |
45 |
table => "ip-${nftables::nat_table_name}", |
46 |
order => $order, |
47 |
content => "${oifname}${src}${dst}${protocol}${port}masquerade"; |
48 |
} |
49 |
} |