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