forward

package
v0.0.0-...-b1da17b Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2018 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ContainerStarted matches the text used in monitoring for a Container Starting up
	ContainerStarted = "ContainerStart"

	// ContainerStopped matches the text used in monitoring for a Container shutting down or being stopped
	ContainerStopped = "ContainerStop"

	// IPTable is the table that all IPTable rules should be added to
	IPTable = "nat"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Forwards map[string][]PortMappings `yaml:",inline"`
}

Config represents the Config File format that can be stored in YAML format

func LoadYAMLConfig

func LoadYAMLConfig(path string) (config Config, err error)

LoadYAMLConfig loads a YAML Port Forwarding config file and builds the appropriate config

func NewConfig

func NewConfig() Config

NewConfig creates and returns initialized config

func (Config) Validate

func (c Config) Validate() (bool, error)

Validate checks a config for correctness. Currently provides the following checks:

  • For each container, makes sure an equal number of Host and Container Ports are provided
  • Makes sure no Host port is used more than once.

type Direction

type Direction int

Direction is used to define the direction of traffic aka if the host is the source or destination of traffic

const (
	// Dst is for traffic where the host is the destination
	Dst Direction = iota
	// Src is fot when the host is the source
	Src
)

func (Direction) String

func (d Direction) String() string

type Forwarder

type Forwarder struct {
	Config
	*lxd.Client
}

Forwarder represents a port forwarding client that can setup and teardown port forwarding for LXD containers

func NewForwarder

func NewForwarder(config Config) (*Forwarder, error)

NewForwarder validates the provided config then creates and returns port forward client

func (Forwarder) Forward

func (f Forwarder) Forward() error

Forward enables forwarding for all containers and port mappings provided in the client config

func (Forwarder) ForwardContainer

func (f Forwarder) ForwardContainer(container string) error

ForwardContainer turns on port forwarding for the provided container Uses iptables to place ipv4 and ipv6 port forwarding rules

func (Forwarder) Reverse

func (f Forwarder) Reverse() error

Reverse disables forwarding for all containers and port mappings provided in the client config

func (Forwarder) ReverseContainer

func (f Forwarder) ReverseContainer(container string) error

ReverseContainer removes port forwarding for the provided container

func (Forwarder) Watch

func (f Forwarder) Watch()

Watch monitors LXD events and identifies when containers named in the config are stopped or started, and disables or enables port forwarding respecitvely

type IPVersion

type IPVersion int

IPVersion is used to modify IPTables rules as needed for iptables vs ip6tables

const (
	//IPv4 is for rules to iptables
	IPv4 IPVersion = iota
	//IPv6 is for rules to ip6tables
	IPv6
)

type PortMappings

type PortMappings struct {
	// Name of the container - May be left empty in YAML config file
	Name string `yaml:"name,omitempty"`
	// Protocol should be "tcp" or "udp"
	Protocol string `yaml:"protocol"`
	// Ports is a mapping of host ports as keys to container ports as values
	Ports map[string]int `yaml:",inline"`
}

PortMappings contains information for mapping ports from a host to a container

func NewPortMappings

func NewPortMappings() PortMappings

NewPortMappings initializes and returns an empty PortMappings struct

Jump to

Keyboard shortcuts

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