Skip to content

Commit

Permalink
simplrule: Allow multiple oifname/iifname
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed Dec 27, 2023
1 parent 29137ea commit 301bc22
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
8 changes: 4 additions & 4 deletions manifests/simplerule.pp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@
Optional[Nftables::Port] $sport = undef,
Optional[Nftables::Addr] $saddr = undef,
Boolean $counter = false,
Optional[String[1]] $iifname = undef,
Optional[String[1]] $oifname = undef,
Variant[Array[String[1]],String[1]] $iifname = [],
Variant[Array[String[1]],String[1]] $oifname = [],
) {
if $dport and !$proto {
fail('Specifying a transport protocol via $proto is mandatory when passing a $dport')
Expand All @@ -96,8 +96,8 @@
'saddr' => $saddr,
'set_type' => $set_type,
'sport' => $sport,
'iifname' => $iifname,
'oifname' => $oifname,
'iifname' => [$iifname].flatten,
'oifname' => [$oifname].flatten,
}
),
order => $order,
Expand Down
18 changes: 10 additions & 8 deletions templates/simplerule.epp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
Optional[Nftables::Addr] $saddr,
String $set_type,
Optional[Nftables::Port] $sport,
Optional[String[1]] $iifname,
Optional[String[1]] $oifname,
Array[String[1]] $iifname,
Array[String[1]] $oifname,
| -%>
<%- if $proto {
$_proto = $proto ? {
Expand Down Expand Up @@ -71,14 +71,16 @@
} else {
$_counter = undef
} -%>
<%- if $iifname {
$_iifname = "iifname \"${iifname}\""
} else {
<%- if empty($iifname) {
$_iifname = undef
} -%>
<%- if $oifname {
$_oifname = "oifname \"${oifname}\""
} else {
$iifdata = $iifname.map |String[1] $interface| { "\"${interface}\"" }.join(', ')
$_iifname = "iifname { ${iifdata} }"
} -%>
<%- if empty($oifname) {
$_oifname = undef
} else {
$oifdata = $oifname.map |String[1] $interface| { "\"${interface}\"" }.join(', ')
$_oifname = "oifname { ${oifdata} }"
} -%>
<%= regsubst(strip([$_ip_version_filter, $_iifname, $_oifname, $_src_port, $_dst_port, $_src_hosts, $_dst_hosts, $_counter, $action, $_comment].join(' ')), '\s+', ' ', 'G') -%>

0 comments on commit 301bc22

Please sign in to comment.