mirror of
https://github.com/speatzle/nfsense.git
synced 2025-05-11 10:58:21 +00:00
Add nftables NAT Action Generation
This commit is contained in:
parent
93ce84e581
commit
a3ab1c7227
1 changed files with 52 additions and 2 deletions
|
@ -3,12 +3,62 @@ package nftables
|
||||||
import (
|
import (
|
||||||
"nfsense.net/nfsense/internal/definitions/config"
|
"nfsense.net/nfsense/internal/definitions/config"
|
||||||
"nfsense.net/nfsense/internal/definitions/firewall"
|
"nfsense.net/nfsense/internal/definitions/firewall"
|
||||||
|
"nfsense.net/nfsense/internal/definitions/object"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GenerateDestinationNatAction(conf config.Config, rule firewall.DestinationNATRule) string {
|
func GenerateDestinationNatAction(conf config.Config, rule firewall.DestinationNATRule) string {
|
||||||
return ""
|
destination := ""
|
||||||
|
|
||||||
|
if rule.Address != nil {
|
||||||
|
addr := conf.Object.Addresses[*rule.Address]
|
||||||
|
|
||||||
|
if addr.Type == object.Host {
|
||||||
|
destination = addr.Host.String()
|
||||||
|
} else {
|
||||||
|
panic("invalid address type")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if rule.Service != nil {
|
||||||
|
serv := conf.Object.Services[*rule.Service]
|
||||||
|
|
||||||
|
if serv.Type == object.TCP || serv.Type == object.UDP {
|
||||||
|
destination += ":" + serv.GetDPort()
|
||||||
|
} else {
|
||||||
|
panic("invalid service type")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "dnat to " + destination
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenerateSourceNatAction(conf config.Config, rule firewall.SourceNATRule) string {
|
func GenerateSourceNatAction(conf config.Config, rule firewall.SourceNATRule) string {
|
||||||
return ""
|
if rule.Type == firewall.Masquerade {
|
||||||
|
return "masqerade"
|
||||||
|
}
|
||||||
|
|
||||||
|
source := ""
|
||||||
|
|
||||||
|
if rule.Address != nil {
|
||||||
|
addr := conf.Object.Addresses[*rule.Address]
|
||||||
|
|
||||||
|
if addr.Type == object.Host {
|
||||||
|
source = addr.Host.String()
|
||||||
|
} else if addr.Type == object.Range {
|
||||||
|
source = addr.Range.String()
|
||||||
|
} else {
|
||||||
|
panic("invalid address type")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if rule.Service != nil {
|
||||||
|
serv := conf.Object.Services[*rule.Service]
|
||||||
|
|
||||||
|
if serv.Type == object.TCP || serv.Type == object.UDP {
|
||||||
|
source += ":" + serv.GetSPort()
|
||||||
|
} else {
|
||||||
|
panic("invalid service type")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "snat to " + source
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue