Manage Forwarding rules

This commit is contained in:
Zoltán Papp
2025-01-24 12:48:52 +01:00
parent 69f48db0a3
commit 4ad5c55795
9 changed files with 649 additions and 281 deletions

View File

@@ -99,6 +99,13 @@ type Manager interface {
// Flush the changes to firewall controller
Flush() error
// AddDNATRule adds a DNAT rule
AddDNATRule(ForwardRule) (Rule, error)
// DeleteDNATRule deletes a DNAT rule
// todo: do you need a string ID or the complete rule?
DeleteDNATRule(Rule) error
}
func GenKey(format string, pair RouterPair) string {

View File

@@ -0,0 +1,26 @@
package manager
import (
"fmt"
"net"
)
// ForwardRule todo figure out better place to this to avoid circular imports
type ForwardRule struct {
Protocol Protocol
DestinationPort Port
TranslatedAddress net.IP
TranslatedPort Port
}
func (r ForwardRule) GetRuleID() string {
return fmt.Sprintf("%s-%s-%s-%s",
r.Protocol,
r.DestinationPort,
r.TranslatedAddress.String(),
r.TranslatedPort)
}
func (r ForwardRule) String() string {
return r.GetRuleID()
}

View File

@@ -4,27 +4,8 @@ import (
"strconv"
)
// Protocol is the protocol of the port
type Protocol string
const (
// ProtocolTCP is the TCP protocol
ProtocolTCP Protocol = "tcp"
// ProtocolUDP is the UDP protocol
ProtocolUDP Protocol = "udp"
// ProtocolICMP is the ICMP protocol
ProtocolICMP Protocol = "icmp"
// ProtocolALL cover all supported protocols
ProtocolALL Protocol = "all"
// ProtocolUnknown unknown protocol
ProtocolUnknown Protocol = "unknown"
)
// Port of the address for firewall rule
// todo Move Protocol and Port and RouterPair to the Firwall package or a separate package
type Port struct {
// IsRange is true Values contains two values, the first is the start port, the second is the end port
IsRange bool

View File

@@ -0,0 +1,22 @@
package manager
// Protocol is the protocol of the port
// todo Move Protocol and Port and RouterPair to the Firwall package or a separate package
type Protocol string
const (
// ProtocolTCP is the TCP protocol
ProtocolTCP Protocol = "tcp"
// ProtocolUDP is the UDP protocol
ProtocolUDP Protocol = "udp"
// ProtocolICMP is the ICMP protocol
ProtocolICMP Protocol = "icmp"
// ProtocolALL cover all supported protocols
ProtocolALL Protocol = "all"
// ProtocolUnknown unknown protocol
ProtocolUnknown Protocol = "unknown"
)