implement creation of SWARM-NAT chain

this is done by two functions:
Test-IptablesChain
Add-IptablesChain
master
lub 5 years ago
parent 055fe0042e
commit 8e8b4b35ac

@ -1,6 +1,39 @@
#Requires -Modules powershell-yaml
$ErrorActionPreference = 'Stop'
function Test-IptablesChain {
param (
[string]$Chain,
[string]$Table = 'nat'
)
$output = iptables -t $Table -S $Chain
$reference = '-N {0}' -f $Chain
#check $output in case $Chain has no rules
#otherwise check the first line with $output[0]
$output.Count -gt 0 `
-and ($output -eq $reference `
-or `
$output[0] -eq $reference)
}
function Add-IptablesChain {
param (
[string]$Chain,
[string]$Table = 'nat'
)
if(-not (Test-IptablesChain -Chain $Chain)) {
iptables -t $Table -N $Chain
}
}
# setup SWARM-NAT chain
$chain = 'SWARM-NAT'
Write-Output ('Create chain {0}' -f $chain)
Add-IptablesChain -Chain $chain
foreach($yaml in (Get-ChildItem -Filter '*.yml')) {
Write-Output ('Processing {0}' -f $yaml)
$definition = Get-Content -Path $yaml -Raw | ConvertFrom-Yaml

Loading…
Cancel
Save