root / templates / simplerule.epp @ 09b07e56
Historique | Voir | Annoter | Télécharger (2,01 ko)
1 | 83382bb5 | Nacho Barrientos | <%- | String $action, |
---|---|---|---|
2 | Optional[String] $comment, |
||
3 | 6739966c | Nacho Barrientos | Boolean $counter, |
4 | Optional[Variant[Stdlib::IP::Address::V6, Stdlib::IP::Address::V4, Pattern[/^@[-a-zA-Z0-9_]+$/]]] $daddr, |
||
5 | 09b07e56 | Nacho Barrientos | Optional[Nftables::Port] $dport, |
6 | 83382bb5 | Nacho Barrientos | Optional[String] $proto, |
7 | 6739966c | Nacho Barrientos | Optional[Variant[Stdlib::IP::Address::V6, Stdlib::IP::Address::V4, Pattern[/^@[-a-zA-Z0-9_]+$/]]] $saddr, |
8 | aaa37172 | Nacho Barrientos | Enum['ip', 'ip6'] $set_type, |
9 | 09b07e56 | Nacho Barrientos | Optional[Nftables::Port] $sport, |
10 | 83382bb5 | Nacho Barrientos | | -%> |
11 | 316bc3f8 | Nacho Barrientos | <%- if $proto { |
12 | $_proto = $proto ? { |
||
13 | /tcp(4|6)?/ => 'tcp', |
||
14 | /udp(4|6)?/ => 'udp', |
||
15 | } |
||
16 | $_ip_version_filter = $proto ? { |
||
17 | /(tcp4|udp4)/ => 'ip version 4', |
||
18 | /(tcp6|udp6)/ => 'ip version 6', |
||
19 | default => undef, |
||
20 | } |
||
21 | } else { |
||
22 | $_ip_version_filter = undef |
||
23 | } -%> |
||
24 | aaa37172 | Nacho Barrientos | <%- if $daddr { |
25 | if $daddr =~ Stdlib::IP::Address::V6 { |
||
26 | $_dst_hosts = "ip6 daddr ${daddr}" |
||
27 | } elsif $daddr =~ Stdlib::IP::Address::V4 { |
||
28 | $_dst_hosts = "ip daddr ${daddr}" |
||
29 | } else { |
||
30 | $_dst_hosts = $set_type ? { |
||
31 | 'ip' => "ip daddr ${daddr}", |
||
32 | 'ip6' => "ip6 daddr ${daddr}", |
||
33 | } |
||
34 | } |
||
35 | } else { |
||
36 | $_dst_hosts = undef |
||
37 | } -%> |
||
38 | 3a469f2b | Nacho Barrientos | <%- if $saddr { |
39 | if $saddr =~ Stdlib::IP::Address::V6 { |
||
40 | $_src_hosts = "ip6 saddr ${saddr}" |
||
41 | } elsif $daddr =~ Stdlib::IP::Address::V4 { |
||
42 | $_src_hosts = "ip saddr ${saddr}" |
||
43 | } else { |
||
44 | $_src_hosts = $set_type ? { |
||
45 | 'ip' => "ip saddr ${saddr}", |
||
46 | 'ip6' => "ip6 saddr ${saddr}", |
||
47 | } |
||
48 | } |
||
49 | } else { |
||
50 | $_src_hosts = undef |
||
51 | } -%> |
||
52 | 3a52fb41 | Nacho Barrientos | <%- if $proto and $dport { |
53 | 6793d286 | Nacho Barrientos | $_dst_port = "${_proto} dport {${Array($dport, true).join(', ')}}" |
54 | 83382bb5 | Nacho Barrientos | } else { |
55 | aaa37172 | Nacho Barrientos | $_dst_port = undef |
56 | 83382bb5 | Nacho Barrientos | } -%> |
57 | <%- if $comment { |
||
58 | $_comment = "comment \"${comment}\"" |
||
59 | } else { |
||
60 | $_comment = undef |
||
61 | } -%> |
||
62 | 77abc10b | Nacho Barrientos | <%- if $proto and $sport { |
63 | $_src_port = "${_proto} sport {${Array($sport, true).join(', ')}}" |
||
64 | } else { |
||
65 | $_src_port = undef |
||
66 | } -%> |
||
67 | d43ced4d | Nacho Barrientos | <%- if $counter { |
68 | $_counter = "counter" |
||
69 | } else { |
||
70 | $_counter = undef |
||
71 | } -%> |
||
72 | 3a469f2b | Nacho Barrientos | <%= regsubst(strip([$_ip_version_filter, $_src_port, $_dst_port, $_src_hosts, $_dst_hosts, $_counter, $action, $_comment].join(' ')), '\s+', ' ', 'G') -%> |