common

package
Version: v0.0.0-...-986d81d Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2018 License: MPL-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package common contains the structs and logic that form the basis of quantum's operation.

All other quantum modules rely on a subset of the functionality provided here.

Index

Examples

Constants

View Source
const (
	// RealDeviceNameEnv is the environment variable that the real network device name is stored in for reloads.
	RealDeviceNameEnv = "_QUANTUM_REAL_DEVICE_NAME_"

	// IPStart - The ip start position within a quantum packet.
	IPStart = 0

	// IPEnd - The ip end position within a quantum packet.
	IPEnd = 4

	// IPLength - The length of the private ip header.
	IPLength = 4

	// PacketStart - The real packet start position within a quantum packet.
	PacketStart = 4

	// MaxPacketLength - The maximum packet size to send via the UDP device.
	// StandardMTU(1500) - IPHeader(20) - UDPHeader(8).
	MaxPacketLength = 1472

	// HeaderSize - The size of the data perpended tp the real packet.
	HeaderSize = IPLength

	// OverflowSize - An extra buffer for overflow of the MTU for plugins and other things to use incase its necessary.
	OverflowSize = 35

	// MTU - The max size packet to receive from the TUN device.
	MTU = MaxPacketLength - HeaderSize - OverflowSize
)

Variables

This section is empty.

Functions

func ArrayEquals

func ArrayEquals(a, b []byte) bool

ArrayEquals returns true if both byte slices contain the same data.

NOTE: this is a very slow func and should be limited in use.

Example
a := []byte{0, 1}
b := []byte{0, 1}
c := []byte{1, 1}

fmt.Println(ArrayEquals(a, b), ArrayEquals(nil, nil), ArrayEquals(a, c), ArrayEquals(a, nil))
Output:

true true false false

func IPtoInt

func IPtoInt(IP net.IP) uint32

IPtoInt takes an ipv4 net.IP and returns a uint32 that represents it.

Example
ipAddr := net.ParseIP("1.0.0.0")
ipInt := IPtoInt(ipAddr)

fmt.Println(ipInt)
Output:

1

func IncrementIP

func IncrementIP(ip net.IP)

IncrementIP will increment the given ipv4 net.IP by 1 in place.

Example
ipAddr := net.ParseIP("0.0.0.1")
IncrementIP(ipAddr)

fmt.Println(ipAddr)
Output:

0.0.0.2

func StringInSlice

func StringInSlice(a string, slice []string) bool

StringInSlice returns true if the string 'a' is contained in the string array 'slice'.

Example
slice := []string{"encryption", "compression"}

fmt.Println(StringInSlice("encryption", slice), StringInSlice("compression", slice), StringInSlice("nonexistent", slice))
Output:

true true false

Types

type Config

type Config struct {
	ConfFile                 string           ``                /* 330-byte string literal not displayed */
	DeviceName               string           ``                /* 331-byte string literal not displayed */
	NumWorkers               int              ``                /* 319-byte string literal not displayed */
	PrivateIP                net.IP           ``                /* 322-byte string literal not displayed */
	ListenIP                 net.IP           ``                /* 321-byte string literal not displayed */
	ListenPort               int              ``                /* 323-byte string literal not displayed */
	FloatingIPs              []net.IP         ``                /* 332-byte string literal not displayed */
	PublicIPv4               net.IP           ``                /* 323-byte string literal not displayed */
	DisableIPv4              bool             ``                /* 331-byte string literal not displayed */
	PublicIPv6               net.IP           ``                /* 323-byte string literal not displayed */
	DisableIPv6              bool             ``                /* 331-byte string literal not displayed */
	DataDir                  string           ``                /* 326-byte string literal not displayed */
	PidFile                  string           ``                /* 325-byte string literal not displayed */
	Forward                  bool             ``                /* 327-byte string literal not displayed */
	Gateway                  net.IP           ``                /* 319-byte string literal not displayed */
	Plugins                  []string         ``                /* 319-byte string literal not displayed */
	Datastore                string           ``                /* 321-byte string literal not displayed */
	DatastorePrefix          string           ``                /* 318-byte string literal not displayed */
	DatastoreSyncInterval    time.Duration    ``                /* 337-byte string literal not displayed */
	DatastoreRefreshInterval time.Duration    ``                /* 344-byte string literal not displayed */
	DatastoreFloatingIPTTL   time.Duration    ``                /* 327-byte string literal not displayed */
	DatastoreEndpoints       []string         ``                /* 321-byte string literal not displayed */
	DatastoreUsername        string           ``                /* 320-byte string literal not displayed */
	DatastorePassword        string           ``                /* 320-byte string literal not displayed */
	DatastoreTLSSkipVerify   bool             ``                /* 333-byte string literal not displayed */
	DatastoreTLSCA           string           ``                /* 335-byte string literal not displayed */
	DatastoreTLSCert         string           ``                /* 339-byte string literal not displayed */
	DatastoreTLSKey          string           ``                /* 332-byte string literal not displayed */
	DTLSSkipVerify           bool             ``                /* 334-byte string literal not displayed */
	DTLSCA                   string           ``                /* 336-byte string literal not displayed */
	DTLSCert                 string           ``                /* 340-byte string literal not displayed */
	DTLSKey                  string           ``                /* 333-byte string literal not displayed */
	StatsRoute               string           ``                /* 325-byte string literal not displayed */
	StatsAddress             string           ``                /* 325-byte string literal not displayed */
	StatsPort                int              ``                /* 327-byte string literal not displayed */
	Network                  string           ``                /* 326-byte string literal not displayed */
	NetworkStaticRange       string           ``                /* 337-byte string literal not displayed */
	NetworkFloatingRange     string           ``                /* 339-byte string literal not displayed */
	NetworkBackend           string           ``                /* 319-byte string literal not displayed */
	NetworkLeaseTime         time.Duration    ``                /* 327-byte string literal not displayed */
	PublicKey                []byte           `internal:"true"` // The public key to use with the encryption plugin.
	PrivateKey               []byte           `internal:"true"` // The private key to use with the encryption plugin.
	PublicSalt               []byte           `internal:"true"` // The public salt to use with the encryption plugin.
	PrivateSalt              []byte           `internal:"true"` // The private salt to use with the encryption plugin.
	Salt                     []byte           `internal:"true"` // The salt to use with the encryption plugin.
	RealDeviceName           string           `internal:"true"` // Used when a rolling restart is triggered to find the correct tun interface
	ReuseFDS                 bool             `internal:"true"` // Used when a rolling restart is triggered which forces quantum to reuse the passed in socket/tun fds
	MachineID                string           `internal:"true"` // The generated machine id for this node
	AuthEnabled              bool             `internal:"true"` // Whether or not datastore authentication is enabled (toggled by setting username/password)
	TLSEnabled               bool             `internal:"true"` // Whether or not tls with the datastore is enabled (toggled by setting the tls parameters at run time)
	IsIPv4Enabled            bool             `internal:"true"` // Whether or not quantum has determined that this node is ipv4 capable
	IsIPv6Enabled            bool             `internal:"true"` // Whether or not quantum has determined that this node is ipv6 capable
	ListenAddr               syscall.Sockaddr `internal:"true"` // The commputed Sockaddr object to bind the underlying udp sockets to
	NetworkConfig            *NetworkConfig   `internal:"true"` // The network config detemined by existence of the object in etcd
	Log                      *Logger          `internal:"true"` // The internal Logger to use
	// contains filtered or unexported fields
}

Config struct that handles marshalling in user supplied configuration data from cli arguments, environment variables, and configuration file entries.

The user supplied configuration is processed via a structured hierarchy:

- Cli arguments override both environment variables and configuration file entries.
- Environment variables will override file entries but can be overridden by cli arguments.
- Configuration file entries will be overridden by both environment variables and cli arguments.
- Defaults are used in the case that the user does not define a configuration argument.

The only exceptions to the above are the two special cli argments '-h'|'--help' or '-v'|'--version' which will output usage information or version information respectively and then exit the application.

func NewConfig

func NewConfig(log *Logger) (*Config, error)

NewConfig creates a new Config struct based on user supplied input.

type Logger

type Logger struct {
	Plain *log.Logger
	Error *log.Logger
	Info  *log.Logger
	Warn  *log.Logger
	Debug *log.Logger
}

Logger struct which allows for a single global point for logging configuration.

func NewLogger

func NewLogger(loggerType LoggerType) *Logger

NewLogger creates a new logger struct based on the supplied LoggerType.

type LoggerType

type LoggerType int

LoggerType will determine the logging level of the logger object created.

const (
	// NoopLogger will noop all logging calls this is only used for testing.
	NoopLogger LoggerType = iota

	// ErrorLogger will only output error logs.
	ErrorLogger

	// WarnLogger will output warn/error logs.
	WarnLogger

	// InfoLogger will output info/warn/error logs.
	InfoLogger

	// DebugLogger will output debug/info/warn/error logs.
	DebugLogger
)

type Mapping

type Mapping struct {
	// The unique machine id within the quantum network.
	MachineID string `json:"machineID"`

	// The private ip address within the quantum network.
	PrivateIP net.IP `json:"privateIP"`

	// The port where quantum is listening for remote packets.
	Port int `json:"port"`

	// Whether or not this mapping represents a floating ip address.
	Floating bool `json:"floating"`

	// The gateway ip this node will forward traffic to.
	Gateway net.IP `json:"gatewayIP"`

	// The public ipv4 address of the node represented by this mapping, which may or may not exist.
	IPv4 net.IP `json:"ipv4,omitempty"`

	// The public ipv6 address of the node represented by this mapping, which may or may not exist.
	IPv6 net.IP `json:"ipv6,omitempty"`

	// The plugins that the node represented by this mapping supports.
	SupportedPlugins []string `json:"plugins,omitempty"`

	// The public key to use with the encryption plugin.
	PublicKey []byte `json:"publicKey,omitempty"`

	// The salt to use with the encryption plugin.
	PublicSalt []byte `json:"salt,omitempty"`

	// The resulting endpoint to send data to the node represented by this mapping.
	Sockaddr syscall.Sockaddr `json:"-"`

	// The resulting endpoint to send data to the node represented by this mapping.
	Address string `json:"-"`

	// The AES object to use for encrypting packets to/from the node represented by this mapping.
	AES *crypto.AES `json:"-"`
}

Mapping represents the relationship between a public/private address along with encryption metadata for a particular node in the quantum network.

func GenerateFloatingMapping

func GenerateFloatingMapping(cfg *Config, i int, mappings map[uint32]*Mapping) (*Mapping, error)

GenerateFloatingMapping will take in the user defined configuration plus the currently defined mappins, in order to determine the floating mapping.

func GenerateLocalMapping

func GenerateLocalMapping(cfg *Config, mappings map[uint32]*Mapping) (*Mapping, error)

GenerateLocalMapping will take in the user defined configuration plus the currently defined mappings, in order to determine the local mapping.

func NewFloatingMapping

func NewFloatingMapping(cfg *Config, i int) *Mapping

NewFloatingMapping generates a new basic Mapping with no cryptographic metadata.

func NewMapping

func NewMapping(cfg *Config) *Mapping

NewMapping generates a new basic Mapping with no cryptographic metadata.

func ParseMapping

func ParseMapping(str string, cfg *Config) (*Mapping, error)

ParseMapping creates a new mapping based on the output of a Mapping.Bytes call.

func (*Mapping) Bytes

func (mapping *Mapping) Bytes() []byte

Bytes returns a byte slice representation of a Mapping object, if there is an error while marshalling data a nil slice is returned.

func (*Mapping) String

func (mapping *Mapping) String() string

Bytes returns a string representation of a Mapping object, if there is an error while marshalling data an empty string is returned.

type NetworkConfig

type NetworkConfig struct {
	// The backend to use for communication.
	Backend string `json:"backend"`

	// The network range that represents the quantum network.
	Network string `json:"network"`

	// The reserved static ip address range which should be skipped for floating and DHCP assignments.
	StaticRange string `json:"staticRange"`

	// The reserved floating ip address range which should be skipped for static and DHCP assignments.
	FloatingRange string `json:"floatingRange"`

	// The length of time to hold the assigned DHCP lease.
	LeaseTime time.Duration `json:"leaseTime"`

	// The base ip address of the quantum network.
	BaseIP net.IP `json:"-"`

	// The IPNet representation of the quantum network.
	IPNet *net.IPNet `json:"-"`

	// The IPNet representation of the reserved static ip address range.
	StaticNet *net.IPNet `json:"-"`

	// The IPNet representation of the reserved floating ip address range.
	FloatingNet *net.IPNet `json:"-"`
}

NetworkConfig object to represent the current network setup.

func ParseNetworkConfig

func ParseNetworkConfig(data []byte) (*NetworkConfig, error)

ParseNetworkConfig from the data stored in the datastore.

func (*NetworkConfig) Bytes

func (networkCfg *NetworkConfig) Bytes() []byte

Bytes returns a byte slice representation of a NetworkConfig object, if there is an error while marshalling data a nil slice is returned.

func (*NetworkConfig) String

func (networkCfg *NetworkConfig) String() string

Bytes returns a string representation of a NetworkConfig object, if there is an error while marshalling data an empty string is returned.

type Payload

type Payload struct {
	// The raw byte array representing the payload, which includes all necessary metadata.
	Raw []byte

	// The packet data within the raw payload.
	Packet []byte

	// The private ip address of the remote peer within the raw payload.
	IPAddress []byte

	// The total length of the payload.
	Length int
}

Payload represents a packet traversing the quantum network.

func NewSockPayload

func NewSockPayload(raw []byte, packetLength int) *Payload

NewSockPayload is used to generate a payload based on a received Socket packet.

func NewTunPayload

func NewTunPayload(raw []byte, packetLength int) *Payload

NewTunPayload is used to generate a payload based on a received TUN packet.

type Signaler

type Signaler struct {
	// contains filtered or unexported fields
}

Signaler struct used to manage os and user signals to the quantum process.

func NewSignaler

func NewSignaler(log *Logger, cfg *Config, fds []int, env map[string]string) *Signaler

NewSignaler generates a new Signaler object, which will watch for new os and user signals passed to the quantum process.

func (*Signaler) Wait

func (sig *Signaler) Wait(exec bool) error

Wait for a configured os or user signal to be passed to the quantum process.

Jump to

Keyboard shortcuts

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