Documentation
¶
Index ¶
- Constants
- func AddrToPrefix(addr netip.Addr) netip.Prefix
- func BundleConfig(config string, rootKey NyPrivateKey) (string, error)
- func CentralConfigValidator(cfg *CentralCfg) error
- func DurationToMetric(d time.Duration) uint32
- func ExpandCentralConfig(cfg *CentralCfg)
- func GetIfIP(itf string, is6 bool) (string, error)
- func MakeSet(prefix []netip.Prefix) *netipx.IPSet
- func MetricToDuration(m uint32) time.Duration
- func NameValidator(s string) error
- func NodeConfigValidator(central *CentralCfg, node *LocalCfg) error
- func OpenBundle(data []byte, key []byte) ([]byte, error)
- func ResolveName(ctx context.Context, host string) ([]netip.Addr, error)
- func ResolveSRV(ctx context.Context, service, proto, name string) (string, uint16, error)
- func SealBundle(data []byte, key []byte) ([]byte, error)
- func SetResolvers(resolvers []string)
- func SignBundle(data []byte, key NyPrivateKey) ([]byte, error)
- func SortPairs[T cmp.Ordered](pairs []Pair[T, T])
- func VerifyBundle(data []byte, key NyPublicKey) ([]byte, error)
- type Advertisement
- type CentralCfg
- func (c *CentralCfg) Clone() (error, *CentralCfg)
- func (e *CentralCfg) FindNodeBy(pkey NyPublicKey) *NodeId
- func (e *CentralCfg) GetClient(node NodeId) ClientCfg
- func (e *CentralCfg) GetNode(node NodeId) NodeCfg
- func (c *CentralCfg) GetNodes() []NodeCfg
- func (e *CentralCfg) GetPeers(curId NodeId) []NodeId
- func (c *CentralCfg) GetPrefixes() []netip.Prefix
- func (e *CentralCfg) GetRouter(node NodeId) RouterCfg
- func (e *CentralCfg) IsClient(node NodeId) bool
- func (e *CentralCfg) IsNode(node NodeId) bool
- func (e *CentralCfg) IsRouter(node NodeId) bool
- func (e *CentralCfg) TryGetNode(node NodeId) *NodeCfg
- type ClientCfg
- type ConfigState
- type DistributionCfg
- type DynamicEndpoint
- func (ep *DynamicEndpoint) Clear()
- func (ep *DynamicEndpoint) Get() (netip.AddrPort, error)
- func (ep *DynamicEndpoint) MarshalYAML() (interface{}, error)
- func (ep *DynamicEndpoint) Parse() (host string, port uint16, err error)
- func (ep *DynamicEndpoint) Refresh(resolveExpiry time.Duration) (netip.AddrPort, error)
- func (ep *DynamicEndpoint) String() string
- func (ep *DynamicEndpoint) UnmarshalYAML(unmarshal func(interface{}) error) error
- type Endpoint
- type FD
- type HTTPPrefixHealth
- type LocalCfg
- type LocalDistributionCfg
- type NeighRoute
- type Neighbour
- type NodeCfg
- type NodeId
- type NyPrivateKey
- type NyPublicKey
- type NylonEndpoint
- func (ep *NylonEndpoint) AsNylonEndpoint() *NylonEndpoint
- func (u *NylonEndpoint) FilteredPing() time.Duration
- func (ep *NylonEndpoint) GetWgEndpoint(device *device.Device) (conn.Endpoint, error)
- func (u *NylonEndpoint) HighRange() time.Duration
- func (u *NylonEndpoint) IsActive() bool
- func (u *NylonEndpoint) IsAlive() bool
- func (u *NylonEndpoint) IsRemote() bool
- func (u *NylonEndpoint) LowRange() time.Duration
- func (u *NylonEndpoint) Metric() uint32
- func (u *NylonEndpoint) Renew()
- func (u *NylonEndpoint) StabilizedPing() time.Duration
- func (u *NylonEndpoint) UpdatePing(ping time.Duration)
- type NylonOptions
- type Pair
- type PingPrefixHealth
- type PrefixHealth
- type PrefixHealthWrapper
- type PubRoute
- type RouterCfg
- type RouterState
- type RouterTunables
- type SelRoute
- type Source
- type StaticPrefixHealth
Constants ¶
const ( INF = ^(uint32)(0) // INFM is the maximum value for a metric that is not a retraction. INFM = INF - 1 // default port DefaultPort = 57175 )
Variables ¶
This section is empty.
Functions ¶
func BundleConfig ¶
func BundleConfig(config string, rootKey NyPrivateKey) (string, error)
BundleConfig first signs the config with the root private key, ensuring the authenticity, then encrypts the message using the bytes of the root public key as the shared key, offering some level of privacy. (assuming the root public key is not shared widely)
func CentralConfigValidator ¶
func CentralConfigValidator(cfg *CentralCfg) error
func DurationToMetric ¶ added in v0.4.0
func ExpandCentralConfig ¶
func ExpandCentralConfig(cfg *CentralCfg)
func MetricToDuration ¶ added in v0.4.0
func NameValidator ¶
func NodeConfigValidator ¶
func NodeConfigValidator(central *CentralCfg, node *LocalCfg) error
func ResolveName ¶ added in v0.4.0
ResolveName resolves a hostname to a list of IP addresses
func ResolveSRV ¶ added in v0.4.0
ResolveSRV resolves an SRV record using the default resolver
func SetResolvers ¶ added in v0.4.0
func SetResolvers(resolvers []string)
SetResolvers configures the global default resolver
func SignBundle ¶
func SignBundle(data []byte, key NyPrivateKey) ([]byte, error)
func VerifyBundle ¶
func VerifyBundle(data []byte, key NyPublicKey) ([]byte, error)
Types ¶
type Advertisement ¶
type CentralCfg ¶
type CentralCfg struct {
Dist *DistributionCfg `yaml:",omitempty"`
Routers []RouterCfg
Clients []ClientCfg
Graph []string
Timestamp int64
ExcludeIPs []netip.Prefix `yaml:"exclude_ips,omitempty"` // split tunnel, default excluded ip ranges for the whole network, if empty, all advertised prefixes will be included
}
func UnbundleConfig ¶
func UnbundleConfig(bundleStr string, pubKey NyPublicKey) (*CentralCfg, error)
func (*CentralCfg) Clone ¶ added in v0.4.0
func (c *CentralCfg) Clone() (error, *CentralCfg)
func (*CentralCfg) FindNodeBy ¶
func (e *CentralCfg) FindNodeBy(pkey NyPublicKey) *NodeId
func (*CentralCfg) GetClient ¶
func (e *CentralCfg) GetClient(node NodeId) ClientCfg
func (*CentralCfg) GetNode ¶
func (e *CentralCfg) GetNode(node NodeId) NodeCfg
func (*CentralCfg) GetNodes ¶
func (c *CentralCfg) GetNodes() []NodeCfg
func (*CentralCfg) GetPeers ¶
func (e *CentralCfg) GetPeers(curId NodeId) []NodeId
func (*CentralCfg) GetPrefixes ¶ added in v0.4.0
func (c *CentralCfg) GetPrefixes() []netip.Prefix
GetPrefixes returns all unique prefixes from all nodes
func (*CentralCfg) GetRouter ¶
func (e *CentralCfg) GetRouter(node NodeId) RouterCfg
func (*CentralCfg) IsClient ¶
func (e *CentralCfg) IsClient(node NodeId) bool
func (*CentralCfg) IsNode ¶
func (e *CentralCfg) IsNode(node NodeId) bool
func (*CentralCfg) IsRouter ¶
func (e *CentralCfg) IsRouter(node NodeId) bool
func (*CentralCfg) TryGetNode ¶
func (e *CentralCfg) TryGetNode(node NodeId) *NodeCfg
type ConfigState ¶ added in v0.4.0
type ConfigState struct {
CentralCfg
LocalCfg
}
ConfigState is a struct so we can easily build test harnesses and reload config
type DistributionCfg ¶
type DistributionCfg struct {
Key NyPublicKey // also used as shared secret, so, although its "public", it's not a good idea to share it.
Repos []string
}
type DynamicEndpoint ¶ added in v0.4.0
type DynamicEndpoint struct {
Value string
// contains filtered or unexported fields
}
DynamicEndpoint represents either an ip:port or a dns name. This may be resolved to a different address at any time
Examples:
- nylon.example.com -> resolves to <ip>:57175 (DefaultPort)
- nylon2.example.com:12345 -> resolves to <ip>:12345
- SRV record: _nylon._udp.example.com. port: 8000 target: nylon3.example.com -> resolves to <ip>:8000
func NewDynamicEndpoint ¶ added in v0.4.0
func NewDynamicEndpoint(value string) *DynamicEndpoint
func (*DynamicEndpoint) Clear ¶ added in v0.4.0
func (ep *DynamicEndpoint) Clear()
func (*DynamicEndpoint) Get ¶ added in v0.4.0
func (ep *DynamicEndpoint) Get() (netip.AddrPort, error)
func (*DynamicEndpoint) MarshalYAML ¶ added in v0.4.0
func (ep *DynamicEndpoint) MarshalYAML() (interface{}, error)
func (*DynamicEndpoint) Parse ¶ added in v0.4.0
func (ep *DynamicEndpoint) Parse() (host string, port uint16, err error)
func (*DynamicEndpoint) String ¶ added in v0.4.0
func (ep *DynamicEndpoint) String() string
func (*DynamicEndpoint) UnmarshalYAML ¶ added in v0.4.0
func (ep *DynamicEndpoint) UnmarshalYAML(unmarshal func(interface{}) error) error
type HTTPPrefixHealth ¶ added in v0.4.0
type HTTPPrefixHealth struct {
Prefix netip.Prefix `yaml:"prefix"`
URL string `yaml:"url"` // the URL to check
Delay *time.Duration `yaml:"delay,omitempty"` // delay between probes
Metric *uint32 `yaml:"metric,omitempty"` // metric override
// contains filtered or unexported fields
}
func (*HTTPPrefixHealth) GetMetric ¶ added in v0.4.0
func (h *HTTPPrefixHealth) GetMetric() uint32
func (*HTTPPrefixHealth) GetPrefix ¶ added in v0.4.0
func (h *HTTPPrefixHealth) GetPrefix() netip.Prefix
func (*HTTPPrefixHealth) Start ¶ added in v0.4.0
func (h *HTTPPrefixHealth) Start(log *slog.Logger, t *RouterTunables)
func (*HTTPPrefixHealth) Stop ¶ added in v0.4.0
func (h *HTTPPrefixHealth) Stop()
type LocalCfg ¶
type LocalCfg struct {
// Node Private Key
Key NyPrivateKey
Id NodeId // unique id for this node
Port uint16 // Address that the data plane can be accessed by
Dist *LocalDistributionCfg `yaml:",omitempty"` // distribution configuration
UseSystemRouting bool `yaml:"use_system_routing,omitempty"` // all packets from peers will come out of the TUN interface
NoNetConfigure bool `yaml:"no_net_configure,omitempty"` // do not configure system networking at all
DnsResolvers []string `yaml:"dns_resolvers,omitempty"` // dns resolvers used by nylon, currently only for config repo
InterfaceName string `yaml:"interface_name,omitempty"` // the name of the nylon interface
LogPath string `yaml:"log_path,omitempty"` // if not empty, nylon will write to this file
UnexcludeIPs []netip.Prefix `yaml:"unexclude_ips,omitempty"` // split tunnel, subtracts from centrally excluded ip ranges
ExcludeIPs []netip.Prefix `yaml:"exclude_ips,omitempty"` // split tunnel, adds to the centrally excluded ip ranges
PreUp []string `yaml:"pre_up,omitempty"` // a list of commands executed in order before the nylon interface is brought up
PreDown []string `yaml:"pre_down,omitempty"` // a list of commands executed in order before the nylon interface is brought down
PostUp []string `yaml:"post_up,omitempty"` // a list of commands executed in order after the nylon interface is brought up
PostDown []string `yaml:"post_down,omitempty"` // a list of commands executed in order after the nylon interface is brought down
}
LocalCfg represents local node-level configuration
type LocalDistributionCfg ¶ added in v0.3.3
type LocalDistributionCfg struct {
Key NyPublicKey
Url string
}
type NeighRoute ¶
type Neighbour ¶
type Neighbour struct {
Id NodeId
Routes map[netip.Prefix]NeighRoute
Eps []Endpoint
}
func (*Neighbour) BestEndpoint ¶
type NodeCfg ¶
type NodeCfg struct {
Id NodeId
PubKey NyPublicKey
Addresses []netip.Addr `yaml:",omitempty"`
Prefixes []PrefixHealthWrapper `yaml:",omitempty"`
}
type NyPrivateKey ¶
type NyPrivateKey [device.NoisePrivateKeySize]byte
func GenerateKey ¶
func GenerateKey() NyPrivateKey
func (NyPrivateKey) MarshalText ¶
func (k NyPrivateKey) MarshalText() ([]byte, error)
func (NyPrivateKey) Pubkey ¶
func (k NyPrivateKey) Pubkey() NyPublicKey
func (*NyPrivateKey) UnmarshalText ¶
func (k *NyPrivateKey) UnmarshalText(text []byte) error
type NyPublicKey ¶
type NyPublicKey [device.NoisePublicKeySize]byte
func (NyPublicKey) MarshalText ¶
func (k NyPublicKey) MarshalText() ([]byte, error)
func (*NyPublicKey) UnmarshalText ¶
func (k *NyPublicKey) UnmarshalText(text []byte) error
type NylonEndpoint ¶
type NylonEndpoint struct {
sync.RWMutex // this mutex is for rtt smoothing and metric calculation
WgEndpoint conn.Endpoint
DynEP *DynamicEndpoint
// contains filtered or unexported fields
}
func NewEndpoint ¶
func NewEndpoint(endpoint *DynamicEndpoint, remoteInit bool, wgEndpoint conn.Endpoint, t *RouterTunables) *NylonEndpoint
func (*NylonEndpoint) AsNylonEndpoint ¶
func (ep *NylonEndpoint) AsNylonEndpoint() *NylonEndpoint
func (*NylonEndpoint) FilteredPing ¶
func (u *NylonEndpoint) FilteredPing() time.Duration
func (*NylonEndpoint) GetWgEndpoint ¶
func (*NylonEndpoint) HighRange ¶
func (u *NylonEndpoint) HighRange() time.Duration
func (*NylonEndpoint) IsActive ¶
func (u *NylonEndpoint) IsActive() bool
func (*NylonEndpoint) IsAlive ¶
func (u *NylonEndpoint) IsAlive() bool
func (*NylonEndpoint) IsRemote ¶
func (u *NylonEndpoint) IsRemote() bool
func (*NylonEndpoint) LowRange ¶
func (u *NylonEndpoint) LowRange() time.Duration
func (*NylonEndpoint) Metric ¶
func (u *NylonEndpoint) Metric() uint32
func (*NylonEndpoint) Renew ¶
func (u *NylonEndpoint) Renew()
func (*NylonEndpoint) StabilizedPing ¶
func (u *NylonEndpoint) StabilizedPing() time.Duration
func (*NylonEndpoint) UpdatePing ¶
func (u *NylonEndpoint) UpdatePing(ping time.Duration)
type NylonOptions ¶ added in v0.4.0
type NylonOptions struct {
DBG_log_probe bool
DBG_log_wireguard bool
DBG_log_repo_updates bool
DBG_log_json bool
DBG_debug bool
DBG_trace bool
DBG_trace_tc bool
}
NylonOptions contains runtime flags set at startup (typically from CLI flags).
func DefaultNylonOptions ¶ added in v0.4.0
func DefaultNylonOptions() NylonOptions
type Pair ¶
type Pair[Ty1, Ty2 any] struct { V1 Ty1 V2 Ty2 }
Pair is only used in-memory, not serialized
func MakeSortedPair ¶
func ParseGraph ¶
ParseGraph Graph syntax is something like this:
Group1 = node1, node2, node3
Group2 = node4, node5
Group1, Group2, OtherNode // Group1, Group2, OtherNode will all be interconnected, but not within Group1 or Group2
Group1, Group1 // every node is connected to every other node
node8, node9 // node8 and node9 will be connected
graph represents the above graph nodes represents a set of unique terminal nodes that the graph will evaluate down to
type PingPrefixHealth ¶ added in v0.4.0
type PingPrefixHealth struct {
Prefix netip.Prefix `yaml:"prefix"`
Addr netip.Addr `yaml:"addr"` // the address to ping
MaxFailures *int `yaml:"max_failures,omitempty"` // number of failures before returning infinite metric
Delay *time.Duration `yaml:"delay,omitempty"` // delay between pings
BindIf string `yaml:"bind_if,omitempty"` // local interface to bind to
Metric *uint32 `yaml:"metric,omitempty"` // metric override
// contains filtered or unexported fields
}
func (*PingPrefixHealth) GetMetric ¶ added in v0.4.0
func (p *PingPrefixHealth) GetMetric() uint32
func (*PingPrefixHealth) GetPrefix ¶ added in v0.4.0
func (p *PingPrefixHealth) GetPrefix() netip.Prefix
func (*PingPrefixHealth) Start ¶ added in v0.4.0
func (p *PingPrefixHealth) Start(log *slog.Logger, t *RouterTunables)
func (*PingPrefixHealth) Stop ¶ added in v0.4.0
func (p *PingPrefixHealth) Stop()
type PrefixHealth ¶ added in v0.4.0
type PrefixHealthWrapper ¶ added in v0.4.0
type PrefixHealthWrapper struct {
PrefixHealth
}
func (PrefixHealthWrapper) MarshalYAML ¶ added in v0.4.0
func (p PrefixHealthWrapper) MarshalYAML() (interface{}, error)
func (*PrefixHealthWrapper) UnmarshalYAML ¶ added in v0.4.0
func (p *PrefixHealthWrapper) UnmarshalYAML(unmarshal func(interface{}) error) error
type PubRoute ¶
type RouterCfg ¶
type RouterCfg struct {
NodeCfg `yaml:",inline"`
Endpoints []*DynamicEndpoint
}
RouterCfg represents a central representation of a node that can route
type RouterState ¶
type RouterState struct {
*RouterTunables
Id NodeId
SelfSeqno map[netip.Prefix]uint16
Routes map[netip.Prefix]SelRoute
Sources map[Source]FD
Neighbours []*Neighbour
// Advertised is a map tracking the prefix and the time it will be advertised until
Advertised map[netip.Prefix]Advertisement
}
func (*RouterState) GetNeighbour ¶
func (s *RouterState) GetNeighbour(node NodeId) *Neighbour
func (*RouterState) StringRoutes ¶
func (s *RouterState) StringRoutes() string
type RouterTunables ¶ added in v0.4.0
type RouterTunables struct {
HopCost uint32 // add a 5 microsecond hop cost to prevent loops on ultra-fast networks.
LargeChangeThreshold uint32 // 100 milliseconds change
SeqnoRequestHopCount uint8
RouteUpdateDelay time.Duration
ProbeDelay time.Duration
ProbeRecoveryDelay time.Duration
ProbeDiscoveryDelay time.Duration
StarvationDelay time.Duration
SeqnoDedupTTL time.Duration
NeighbourIOFlushDelay time.Duration
SafeMTU int
// WindowSamples is the sliding window size
WindowSamples int
OutlierPercentage float64
// MinimumConfidenceWindow is the minimum number of samples before we lower the ping
MinimumConfidenceWindow int
GcDelay time.Duration
LinkDeadThreshold time.Duration
RouteExpiryTime time.Duration
// client configuration
ClientKeepaliveInterval time.Duration
ClientDeadThreshold time.Duration
// central updates
CentralUpdateDelay time.Duration
// healthcheck defaults
HealthCheckDelay time.Duration
HealthCheckMaxFailures int
EndpointResolveExpiry time.Duration
EndpointResolveDelay time.Duration
}
RouterTunables contains all timing and algorithm parameters for the router. These are set once at startup and should not be mutated after the Nylon instance starts.
func DefaultRouterTunables ¶ added in v0.4.0
func DefaultRouterTunables() RouterTunables
type SelRoute ¶
type StaticPrefixHealth ¶ added in v0.4.0
type StaticPrefixHealth struct {
Prefix netip.Prefix `yaml:"prefix"`
Metric uint32 `yaml:"metric,omitempty"` // the metric to advertise for this prefix
}
StaticPrefixHealth represents a static prefix configuration, always advertised with the same metric
func (*StaticPrefixHealth) GetMetric ¶ added in v0.4.0
func (s *StaticPrefixHealth) GetMetric() uint32
func (*StaticPrefixHealth) GetPrefix ¶ added in v0.4.0
func (s *StaticPrefixHealth) GetPrefix() netip.Prefix
func (*StaticPrefixHealth) Start ¶ added in v0.4.0
func (s *StaticPrefixHealth) Start(log *slog.Logger, t *RouterTunables)
func (*StaticPrefixHealth) Stop ¶ added in v0.4.0
func (s *StaticPrefixHealth) Stop()