2023-03-16 10:00:08 +01:00
|
|
|
package firewall
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Rule abstraction should be implemented by each firewall manager
|
|
|
|
//
|
|
|
|
// Each firewall type for different OS can use different type
|
|
|
|
// of the properties to hold data of the created rule
|
|
|
|
type Rule interface {
|
|
|
|
// GetRuleID returns the rule id
|
|
|
|
GetRuleID() string
|
|
|
|
}
|
|
|
|
|
2023-05-29 16:00:18 +02:00
|
|
|
// RuleDirection is the traffic direction which a rule is applied
|
|
|
|
type RuleDirection int
|
2023-03-16 10:00:08 +01:00
|
|
|
|
|
|
|
const (
|
2023-05-29 16:00:18 +02:00
|
|
|
// RuleDirectionIN applies to filters that handlers incoming traffic
|
|
|
|
RuleDirectionIN RuleDirection = iota
|
|
|
|
// RuleDirectionOUT applies to filters that handlers outgoing traffic
|
|
|
|
RuleDirectionOUT
|
2023-03-16 10:00:08 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Action is the action to be taken on a rule
|
|
|
|
type Action int
|
|
|
|
|
|
|
|
const (
|
2023-05-29 16:00:18 +02:00
|
|
|
// ActionUnknown is a unknown action
|
|
|
|
ActionUnknown Action = iota
|
2023-03-16 10:00:08 +01:00
|
|
|
// ActionAccept is the action to accept a packet
|
2023-05-29 16:00:18 +02:00
|
|
|
ActionAccept
|
2023-03-16 10:00:08 +01:00
|
|
|
// ActionDrop is the action to drop a packet
|
|
|
|
ActionDrop
|
|
|
|
)
|
|
|
|
|
|
|
|
// Manager is the high level abstraction of a firewall manager
|
|
|
|
//
|
|
|
|
// It declares methods which handle actions required by the
|
|
|
|
// Netbird client for ACL and routing functionality
|
|
|
|
type Manager interface {
|
|
|
|
// AddFiltering rule to the firewall
|
2023-05-29 16:00:18 +02:00
|
|
|
//
|
|
|
|
// If comment argument is empty firewall manager should set
|
|
|
|
// rule ID as comment for the rule
|
2023-03-16 10:00:08 +01:00
|
|
|
AddFiltering(
|
|
|
|
ip net.IP,
|
2023-05-29 16:00:18 +02:00
|
|
|
proto Protocol,
|
|
|
|
sPort *Port,
|
|
|
|
dPort *Port,
|
|
|
|
direction RuleDirection,
|
2023-03-16 10:00:08 +01:00
|
|
|
action Action,
|
|
|
|
comment string,
|
|
|
|
) (Rule, error)
|
|
|
|
|
|
|
|
// DeleteRule from the firewall by rule definition
|
|
|
|
DeleteRule(rule Rule) error
|
|
|
|
|
|
|
|
// Reset firewall to the default state
|
|
|
|
Reset() error
|
|
|
|
|
|
|
|
// TODO: migrate routemanager firewal actions to this interface
|
|
|
|
}
|