types

package
v0.78.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2026 License: BSD-3-Clause Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FirewallRuleDirectionIN  = 0
	FirewallRuleDirectionOUT = 1
)
View Source
const (
	// AllowedIPsFormat generates Wireguard AllowedIPs format (e.g. 100.64.30.1/32)
	AllowedIPsFormat = "%s/32"
	// AllowedIPsV6Format generates AllowedIPs format for v6 (e.g. fd12:3456:7890::1/128)
	AllowedIPsV6Format = "%s/128"
)
View Source
const (
	// PolicyTrafficActionAccept indicates that the traffic is accepted
	PolicyTrafficActionAccept = PolicyTrafficActionType("accept")
	// PolicyTrafficActionDrop indicates that the traffic is dropped
	PolicyTrafficActionDrop = PolicyTrafficActionType("drop")
)
View Source
const (
	// PolicyRuleProtocolALL type of traffic
	PolicyRuleProtocolALL = PolicyRuleProtocolType("all")
	// PolicyRuleProtocolTCP type of traffic
	PolicyRuleProtocolTCP = PolicyRuleProtocolType("tcp")
	// PolicyRuleProtocolUDP type of traffic
	PolicyRuleProtocolUDP = PolicyRuleProtocolType("udp")
	// PolicyRuleProtocolICMP type of traffic
	PolicyRuleProtocolICMP = PolicyRuleProtocolType("icmp")
	// PolicyRuleProtocolNetbirdSSH type of traffic
	PolicyRuleProtocolNetbirdSSH = PolicyRuleProtocolType("netbird-ssh")
)

Variables

This section is empty.

Functions

func ParseRuleString

func ParseRuleString(rule string) (PolicyRuleProtocolType, RulePortRange, error)

Types

type AccountSettingsInfo

type AccountSettingsInfo struct {
	PeerLoginExpirationEnabled      bool
	PeerLoginExpiration             time.Duration
	PeerInactivityExpirationEnabled bool
	PeerInactivityExpiration        time.Duration
}

type FirewallRule

type FirewallRule struct {
	// PolicyID is the ID of the policy this rule is derived from
	PolicyID string

	// PeerIP of the peer
	PeerIP string

	// Direction of the traffic
	Direction int

	// Action of the traffic
	Action string

	// Protocol of the traffic
	Protocol string

	// Port of the traffic
	Port string

	// PortRange represents the range of ports for a firewall rule
	PortRange RulePortRange
}

FirewallRule is a rule of the firewall.

func AppendIPv6FirewallRule

func AppendIPv6FirewallRule(rules []*FirewallRule, rulesExists map[string]struct{}, peer, targetPeer *nmdata.Peer, rule *nmdata.PolicyRule, rc FirewallRuleContext) []*FirewallRule

func ExpandPortsAndRanges

func ExpandPortsAndRanges(base FirewallRule, rule *nmdata.PolicyRule, peer *nmdata.Peer) []*FirewallRule

ExpandPortsAndRanges expands Ports and PortRanges of a rule into individual firewall rules.

func (*FirewallRule) Equal

func (r *FirewallRule) Equal(other *FirewallRule) bool

Equal checks if two firewall rules are equal.

type FirewallRuleContext

type FirewallRuleContext struct {
	Direction   int
	DirStr      string
	ProtocolStr string
	ActionStr   string
	PortsJoined string
}

type ForwardingRule

type ForwardingRule struct {
	RuleProtocol      string
	DestinationPorts  RulePortRange
	TranslatedAddress net.IP
	TranslatedPorts   RulePortRange
}

func (*ForwardingRule) Equal

func (f *ForwardingRule) Equal(other *ForwardingRule) bool

func (*ForwardingRule) ToProto

func (f *ForwardingRule) ToProto() *proto.ForwardingRule

type GroupCompact

type GroupCompact struct {
	Name        string
	PeerIndexes []int
}

type LookupMap

type LookupMap map[string]struct{}

type NetworkMap

type NetworkMap struct {
	Peers               []*nmdata.Peer
	Network             *nmdata.Network
	Routes              []*nmdata.Route
	DNSConfig           nbdns.Config
	OfflinePeers        []*nmdata.Peer
	FirewallRules       []*FirewallRule
	RoutesFirewallRules []*RouteFirewallRule
	ForwardingRules     []*ForwardingRule
	AuthorizedUsers     map[string]map[string]struct{}
	EnableSSH           bool
	// ForceRoutingPeerDNSResolution forces the peer to run/use routing-peer DNS
	// resolution regardless of the account-global setting, for reverse-proxy
	// domain targets.
	ForceRoutingPeerDNSResolution bool
}

func CalculateNetworkMapFromComponents

func CalculateNetworkMapFromComponents(ctx context.Context, components *NetworkMapComponents) *NetworkMap

func (*NetworkMap) Merge

func (nm *NetworkMap) Merge(other *NetworkMap)

type NetworkMapComponents

type NetworkMapComponents struct {
	PeerID string

	Network          *nmdata.Network
	AccountSettings  *nmdata.AccountSettingsInfo
	DNSSettings      *nmdata.DNSSettings
	CustomZoneDomain string

	Peers               map[string]*nmdata.Peer
	Groups              map[string]*nmdata.Group
	Policies            []*nmdata.Policy
	Routes              []*nmdata.Route
	NameServerGroups    []*nmdata.NameServerGroup
	AllDNSRecords       []nmdata.SimpleRecord
	AccountZones        []nmdata.CustomZone
	ResourcePoliciesMap map[string][]*nmdata.Policy
	RoutersMap          map[string]map[string]*nmdata.NetworkRouter
	NetworkResources    []*nmdata.NetworkResource

	GroupIDToUserIDs   map[string][]string
	AllowedUserIDs     map[string]struct{}
	PostureFailedPeers map[string]map[string]struct{}

	RouterPeers map[string]*nmdata.Peer

	// NetworkXIDToPublicID maps Network.ID (xid) → PublicID.
	// Consumed by the envelope encoder to
	// translate RoutersMap keys and NetworkResource.NetworkID references
	// to compact uint32 ids. Legacy Calculate() doesn't consult it.
	NetworkXIDToPublicID map[string]string

	// PostureCheckXIDToPublicID maps posture.Checks.ID (xid) → PublicID.
	// Same role as NetworkXIDToPublicID, used for PostureFailedPeers keys and
	// policy SourcePostureChecks references.
	PostureCheckXIDToPublicID map[string]string

	// ForceRoutingPeerDNSResolution forces the peer to run/use routing-peer DNS
	// resolution regardless of the account-global setting, for reverse-proxy
	// domain targets.
	ForceRoutingPeerDNSResolution bool
	// contains filtered or unexported fields
}

func EmptyNetworkMapComponents

func EmptyNetworkMapComponents(nm *NetworkMapComponents) *NetworkMapComponents

func (*NetworkMapComponents) Calculate

func (c *NetworkMapComponents) Calculate(ctx context.Context) *NetworkMap

func (*NetworkMapComponents) GetGroupInfo

func (c *NetworkMapComponents) GetGroupInfo(groupID string) *nmdata.Group

func (*NetworkMapComponents) GetPeerGroups

func (c *NetworkMapComponents) GetPeerGroups(peerID string) map[string]struct{}

func (*NetworkMapComponents) GetPeerInfo

func (c *NetworkMapComponents) GetPeerInfo(peerID string) *nmdata.Peer

func (*NetworkMapComponents) GetRouterPeerInfo

func (c *NetworkMapComponents) GetRouterPeerInfo(peerID string) *nmdata.Peer

func (*NetworkMapComponents) IsEmpty

func (c *NetworkMapComponents) IsEmpty() bool

func (*NetworkMapComponents) IsPeerInGroup

func (c *NetworkMapComponents) IsPeerInGroup(peerID, groupID string) bool

func (*NetworkMapComponents) ToCompact

func (*NetworkMapComponents) ValidatePostureChecksOnPeer

func (c *NetworkMapComponents) ValidatePostureChecksOnPeer(peerID string, postureCheckIDs []string) bool

type NetworkMapComponentsCompact

type NetworkMapComponentsCompact struct {
	PeerID string

	Network          *nmdata.Network
	AccountSettings  *nmdata.AccountSettingsInfo
	DNSSettings      *nmdata.DNSSettings
	CustomZoneDomain string

	AllPeers          []*nmdata.Peer
	PeerIndexes       []int
	RouterPeerIndexes []int

	Groups              map[string]*GroupCompact
	AllPolicies         []*nmdata.Policy
	PolicyIndexes       []int
	ResourcePoliciesMap map[string][]int
	Routes              []*nmdata.Route
	NameServerGroups    []*nmdata.NameServerGroup
	AllDNSRecords       []nmdata.SimpleRecord
	AccountZones        []nmdata.CustomZone

	RoutersMap       map[string]map[string]*nmdata.NetworkRouter
	NetworkResources []*nmdata.NetworkResource

	GroupIDToUserIDs   map[string][]string
	AllowedUserIDs     map[string]struct{}
	PostureFailedPeers map[string]map[string]struct{}
}

func (*NetworkMapComponentsCompact) ToFull

type PolicyRuleProtocolType

type PolicyRuleProtocolType string

PolicyRuleProtocolType type of traffic

type PolicyTrafficActionType

type PolicyTrafficActionType string

PolicyTrafficActionType action type for the firewall

type ResourceType

type ResourceType string
const (
	ResourceTypePeer   ResourceType = "peer"
	ResourceTypeDomain ResourceType = "domain"
	ResourceTypeHost   ResourceType = "host"
	ResourceTypeSubnet ResourceType = "subnet"
)

func (ResourceType) Valid added in v0.78.0

func (t ResourceType) Valid() bool

type RouteFirewallRule

type RouteFirewallRule struct {
	// PolicyID is the ID of the policy this rule is derived from
	PolicyID string

	// RouteID is the ID of the route this rule belongs to.
	RouteID route.ID

	// SourceRanges IP ranges of the routing peers.
	SourceRanges []string

	// Action of the traffic when the rule is applicable
	Action string

	// Destination a network prefix for the routed traffic
	Destination string

	// Protocol of the traffic
	Protocol string

	// Port of the traffic
	Port uint16

	// PortRange represents the range of ports for a firewall rule
	PortRange RulePortRange

	// Domains list of network domains for the routed traffic
	Domains domain.List

	// isDynamic indicates whether the rule is for DNS routing
	IsDynamic bool
}

RouteFirewallRule a firewall rule applicable for a routed network.

func GenerateRouteFirewallRules

func GenerateRouteFirewallRules(ctx context.Context, route *nmdata.Route, rule *nmdata.PolicyRule, groupPeers []*nmdata.Peer, direction int, includeIPv6 bool) []*RouteFirewallRule

GenerateRouteFirewallRules generates a list of firewall rules for a given route. For static routes, source ranges match the destination family (v4 or v6). For dynamic routes (domain-based), separate v4 and v6 rules are generated so the routing peer's forwarding chain allows both address families.

func (*RouteFirewallRule) Equal

func (r *RouteFirewallRule) Equal(other *RouteFirewallRule) bool

type RulePortRange

type RulePortRange struct {
	Start uint16
	End   uint16
}

RulePortRange represents a range of ports for a firewall rule.

func (*RulePortRange) Equal

func (r *RulePortRange) Equal(other *RulePortRange) bool

func (*RulePortRange) ToProto

func (r *RulePortRange) ToProto() *proto.PortInfo

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL