Skip to content

Commit

Permalink
refactor epp
Browse files Browse the repository at this point in the history
  • Loading branch information
stjmt committed Jul 31, 2024
1 parent 5581794 commit c5961ce
Showing 1 changed file with 20 additions and 34 deletions.
54 changes: 20 additions & 34 deletions templates/simplerule.epp
Original file line number Diff line number Diff line change
Expand Up @@ -24,48 +24,34 @@
$_ip_version_filter = undef
} -%>
<%- if $daddr {
if $daddr =~ Stdlib::IP::Address::V6 {
$_dst_hosts = "ip6 daddr ${daddr}"
} elsif $daddr =~ Stdlib::IP::Address::V4 {
$_dst_hosts = "ip daddr ${daddr}"
} elsif $daddr =~ Array[Stdlib::IP::Address::V6] {
$_dst_hosts = "ip6 daddr {${Array($daddr, true).join(', ')}}"
} elsif $daddr =~ Array[Stdlib::IP::Address::V4] {
$_dst_hosts = "ip daddr {${Array($daddr, true).join(', ')}}"
} elsif $daddr =~ Array {
$_dst_hosts = $set_type ? {
'ip' => "ip daddr {${Array($daddr, true).join(', ')}}",
'ip6' => "ip6 daddr {${Array($daddr, true).join(', ')}}",
}
$_daddr = ($daddr =~ Array) ? {
true => "{${$daddr.join(', ')}}",
default => $daddr,
}
if $daddr =~ Stdlib::IP::Address::V6 or $daddr =~ Array[Stdlib::IP::Address::V6] {
$_daddr_type = 'ip6'
} elsif $saddr =~ Stdlib::IP::Address::V4 or $daddr =~ Array[Stdlib::IP::Address::V4] {
$_daddr_type = 'ip'
} else {
$_dst_hosts = $set_type ? {
'ip' => "ip daddr ${daddr}",
'ip6' => "ip6 daddr ${daddr}",
}
$_daddr_type = $set_type # ip or ip6
}
$_src_hosts = "${_saddr_type} daddr ${_saddr}"
} else {
$_dst_hosts = undef
} -%>
<%- if $saddr {
if $saddr =~ Stdlib::IP::Address::V6 {
$_src_hosts = "ip6 saddr ${saddr}"
} elsif $saddr =~ Stdlib::IP::Address::V4 {
$_src_hosts = "ip saddr ${saddr}"
} elsif $saddr =~ Array[Stdlib::IP::Address::V6] {
$_src_hosts = "ip6 saddr {${Array($saddr, true).join(', ')}}"
} elsif $saddr =~ Array[Stdlib::IP::Address::V4] {
$_src_hosts = "ip saddr {${Array($saddr, true).join(', ')}}"
} elsif $saddr =~ Array {
$_src_hosts = $set_type ? {
'ip' => "ip saddr {${Array($saddr, true).join(', ')}}",
'ip6' => "ip6 saddr {${Array($saddr, true).join(', ')}}",
}
$_saddr = ($saddr =~ Array) ? {
true => "{${$saddr.join(', ')}}",
default => $saddr,
}
if $saddr =~ Stdlib::IP::Address::V6 or $saddr =~ Array[Stdlib::IP::Address::V6] {
$_saddr_type = 'ip6'
} elsif $saddr =~ Stdlib::IP::Address::V4 or $saddr =~ Array[Stdlib::IP::Address::V4] {
$_saddr_type = 'ip'
} else {
$_src_hosts = $set_type ? {
'ip' => "ip saddr ${saddr}",
'ip6' => "ip6 saddr ${saddr}",
}
$_saddr_type = $set_type # ip or ip6
}
$_src_hosts = "${_saddr_type} saddr ${_saddr}"
} else {
$_src_hosts = undef
} -%>
Expand Down

0 comments on commit c5961ce

Please sign in to comment.