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