add check in nft rules for dual stack internet gateway

This commit is contained in:
Matthew R. Kasun
2022-09-12 15:11:19 -04:00
parent 5d27db6e22
commit e4761ef21b

View File

@@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"net"
"strings" "strings"
"time" "time"
@@ -334,6 +335,9 @@ func firewallNFTCommandsCreateEgress(networkInterface string, gatewayInterface s
postUp += "nft 'add chain ip nat prerouting { type nat hook prerouting priority 0 ;}' ; " postUp += "nft 'add chain ip nat prerouting { type nat hook prerouting priority 0 ;}' ; "
postUp += "nft 'add chain ip nat postrouting { type nat hook postrouting priority 0 ;}' ; " postUp += "nft 'add chain ip nat postrouting { type nat hook postrouting priority 0 ;}' ; "
for _, networkCIDR := range gatewayranges { for _, networkCIDR := range gatewayranges {
if net.ParseIP(networkCIDR).To16() != nil {
continue
}
postUp += "nft add rule nat postrouting iifname " + networkInterface + " oifname " + gatewayInterface + " ip saddr " + networkCIDR + " masquerade ; " postUp += "nft add rule nat postrouting iifname " + networkInterface + " oifname " + gatewayInterface + " ip saddr " + networkCIDR + " masquerade ; "
} }