root / manifests / chain.pp @ fcb1d356
Historique | Voir | Annoter | Télécharger (1,58 ko)
1 |
# manage a chain |
---|---|
2 |
define nftables::chain ( |
3 |
Pattern[/^(ip|ip6|inet)-[a-zA-Z0-9_]+$/] $table = 'inet-filter', |
4 |
Pattern[/^[a-zA-Z0-9_]+$/] $chain = $title, |
5 |
Optional[Pattern[/^\d\d-[a-zA-Z0-9_]+$/]] $inject = undef, |
6 |
Optional[String] $inject_iif = undef, |
7 |
Optional[String] $inject_oif = undef, |
8 |
) { |
9 |
$concat_name = "nftables-${table}-chain-${chain}" |
10 |
|
11 |
concat { |
12 |
$concat_name: |
13 |
path => "/etc/nftables/puppet-preflight/${table}-chain-${chain}.nft", |
14 |
owner => root, |
15 |
group => root, |
16 |
mode => '0640', |
17 |
ensure_newline => true, |
18 |
require => Package['nftables'], |
19 |
} ~> Exec['nft validate'] -> file { |
20 |
"/etc/nftables/puppet/${table}-chain-${chain}.nft": |
21 |
ensure => file, |
22 |
source => "/etc/nftables/puppet-preflight/${table}-chain-${chain}.nft", |
23 |
owner => root, |
24 |
group => root, |
25 |
mode => '0640', |
26 |
} ~> Service['nftables'] |
27 |
|
28 |
concat::fragment { |
29 |
default: |
30 |
target => $concat_name; |
31 |
"${concat_name}-header": |
32 |
order => '00', |
33 |
content => "# Start of fragment order:00 ${chain} header\nchain ${chain} {"; |
34 |
"${concat_name}-footer": |
35 |
order => '99', |
36 |
content => "# Start of fragment order:99 ${chain} footer\n}"; |
37 |
} |
38 |
|
39 |
if $inject { |
40 |
$data = split($inject, '-') |
41 |
$iif = $inject_iif ? { |
42 |
undef => '', |
43 |
default => "iifname ${inject_iif} ", |
44 |
} |
45 |
$oif = $inject_oif ? { |
46 |
undef => '', |
47 |
default => "oifname ${inject_oif} ", |
48 |
} |
49 |
nftables::rule { "${data[1]}-jump_${chain}": |
50 |
order => $data[0], |
51 |
content => "${iif}${oif}jump ${chain}", |
52 |
} |
53 |
} |
54 |
} |