Documentation
¶
Overview ¶
Package networkmap contains the shared NetworkMap helpers that both the management server and the client agent need.
The proto-conversion helpers (types.NetworkMap → proto.NetworkMap) live here so the client can run the same conversion locally after deriving its NetworkMap from a NetworkMapEnvelope, without taking a dependency on the server-side conversion package (which pulls in cloud integrations and is otherwise an unwanted internal import on the client).
The helpers are pure functions over inputs — no caches, no IO, no logging beyond a context-aware error log when an individual user-id hash fails.
Index ¶
- func AppendRemotePeerConfig(dst []*proto.RemotePeerConfig, peers []*types.ComponentPeer, dnsName string, ...) []*proto.RemotePeerConfig
- func BuildAuthorizedUsersProto(ctx context.Context, authorizedUsers map[string]map[string]struct{}) ([][]byte, map[string]*proto.MachineUserIndexes)
- func ConvertToProtoCustomZone(zone nbdns.CustomZone) *proto.CustomZone
- func ConvertToProtoNameServerGroup(nsGroup *nbdns.NameServerGroup) *proto.NameServerGroup
- func DecodeEnvelope(env *proto.NetworkMapEnvelope) (*types.NetworkMapComponents, error)
- func GetProtoAction(action string) proto.RuleAction
- func GetProtoDirection(direction int) proto.RuleDirection
- func GetProtoPortInfo(rule *types.RouteFirewallRule) *proto.PortInfo
- func GetProtoProtocol(protocol string) proto.RuleProtocol
- func ShouldUsePortRange(rule *proto.FirewallRule) bool
- func ToProtocolDNSConfig(update nbdns.Config, cache DNSConfigCache, forwardPort int64) *proto.DNSConfig
- func ToProtocolFirewallRules(rules []*types.FirewallRule, includeIPv6, useSourcePrefixes bool) []*proto.FirewallRule
- func ToProtocolRoute(route *nbroute.Route) *proto.Route
- func ToProtocolRoutes(routes []*nbroute.Route) []*proto.Route
- func ToProtocolRoutesFirewallRules(rules []*types.RouteFirewallRule) []*proto.RouteFirewallRule
- type DNSConfigCache
- type EnvelopeResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendRemotePeerConfig ¶
func AppendRemotePeerConfig(dst []*proto.RemotePeerConfig, peers []*types.ComponentPeer, dnsName string, includeIPv6 bool) []*proto.RemotePeerConfig
AppendRemotePeerConfig appends typed peers as proto.RemotePeerConfig entries to dst and returns the result.
func BuildAuthorizedUsersProto ¶
func BuildAuthorizedUsersProto(ctx context.Context, authorizedUsers map[string]map[string]struct{}) ([][]byte, map[string]*proto.MachineUserIndexes)
BuildAuthorizedUsersProto deduplicates user-IDs into a hashed list and builds per-machine-user index maps. Returns (hashedUsers, machineUsers). Errors from individual hash failures are logged via the provided context; they leave the offending user out of the result but don't abort the build.
func ConvertToProtoCustomZone ¶
func ConvertToProtoCustomZone(zone nbdns.CustomZone) *proto.CustomZone
ConvertToProtoCustomZone converts an nbdns.CustomZone to its proto form.
func ConvertToProtoNameServerGroup ¶
func ConvertToProtoNameServerGroup(nsGroup *nbdns.NameServerGroup) *proto.NameServerGroup
ConvertToProtoNameServerGroup converts a NameServerGroup to its proto form.
func DecodeEnvelope ¶
func DecodeEnvelope(env *proto.NetworkMapEnvelope) (*types.NetworkMapComponents, error)
DecodeEnvelope converts a NetworkMapEnvelope into a NetworkMapComponents the client can run Calculate() over. Every ID-reference on the wire is a xid from corresponding public_id field.
ID scheme on the client side:
Peers base64(wg_pub_key) // stable across snapshots
func GetProtoAction ¶
func GetProtoAction(action string) proto.RuleAction
GetProtoAction converts the action to proto.RuleAction.
func GetProtoDirection ¶
func GetProtoDirection(direction int) proto.RuleDirection
GetProtoDirection converts the direction to proto.RuleDirection.
func GetProtoPortInfo ¶
func GetProtoPortInfo(rule *types.RouteFirewallRule) *proto.PortInfo
GetProtoPortInfo converts route-firewall-rule port info to proto.PortInfo.
func GetProtoProtocol ¶
func GetProtoProtocol(protocol string) proto.RuleProtocol
GetProtoProtocol converts the protocol to proto.RuleProtocol.
func ShouldUsePortRange ¶
func ShouldUsePortRange(rule *proto.FirewallRule) bool
ShouldUsePortRange reports whether the firewall rule should use a port range rather than a single port (TCP/UDP without a single port).
func ToProtocolDNSConfig ¶
func ToProtocolDNSConfig(update nbdns.Config, cache DNSConfigCache, forwardPort int64) *proto.DNSConfig
ToProtocolDNSConfig converts nbdns.Config to proto.DNSConfig. If cache is non-nil, NameServerGroup proto values are cached by NSG.ID across calls — the server amortises this across peers, the client passes nil.
func ToProtocolFirewallRules ¶
func ToProtocolFirewallRules(rules []*types.FirewallRule, includeIPv6, useSourcePrefixes bool) []*proto.FirewallRule
ToProtocolFirewallRules converts the firewall rules to the protocol form. When useSourcePrefixes is true, the compact SourcePrefixes field is populated alongside the deprecated PeerIP for forward compatibility. Wildcard rules ("0.0.0.0") are expanded into separate v4/v6 SourcePrefixes when includeIPv6 is true.
func ToProtocolRoute ¶
ToProtocolRoute converts one typed route to its proto form.
func ToProtocolRoutes ¶
ToProtocolRoutes converts a slice of typed routes to their proto form.
func ToProtocolRoutesFirewallRules ¶
func ToProtocolRoutesFirewallRules(rules []*types.RouteFirewallRule) []*proto.RouteFirewallRule
ToProtocolRoutesFirewallRules converts a slice of typed route-firewall rules to proto.
Types ¶
type DNSConfigCache ¶
type DNSConfigCache interface {
GetNameServerGroup(key string) (*proto.NameServerGroup, bool)
SetNameServerGroup(key string, value *proto.NameServerGroup)
}
DNSConfigCache is the cache contract for amortising NameServerGroup proto-conversion across peers in the same account. Server uses a concrete implementation; client passes nil (no cross-peer caching needed when rebuilding a single NetworkMap from an envelope).
type EnvelopeResult ¶
type EnvelopeResult struct {
NetworkMap *proto.NetworkMap
Components *types.NetworkMapComponents
}
EnvelopeResult is what the client engine consumes after receiving a component-format NetworkMap. Both fields are populated:
- NetworkMap is the *proto.NetworkMap shape the engine reads today via update.GetNetworkMap() — built from the envelope's components by running Calculate() locally + converting back through the shared proto helpers + merging the optional ProxyPatch.
- Components is the *types.NetworkMapComponents the engine retains so future incremental delta updates have a base to apply changes against. The client keeps it under its sync lock.
func EnvelopeToNetworkMap ¶
func EnvelopeToNetworkMap(ctx context.Context, env *proto.NetworkMapEnvelope, localPeerKey, dnsName string) (*EnvelopeResult, error)
EnvelopeToNetworkMap is the full client-side pipeline: decode the component envelope back to a typed NetworkMapComponents, run Calculate() locally to produce the typed NetworkMap, convert it to the wire form the engine consumes, and fold in any ProxyPatch the server attached.
localPeerKey is the receiving peer's WG pub key (used to derive includeIPv6 / useSourcePrefixes from the receiving peer's own record in the components struct, mirroring legacy ToSyncResponse behaviour).
dnsName is the account's DNS domain ("netbird.cloud" etc.); used when rebuilding the per-peer FQDNs that proto.RemotePeerConfig carries.