boxnet

package
v0.0.0-...-e411b72 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

README

boxnet is basically a wrapper around github.com/vishvananda/netlink to extend it by adding the concept of models. Its current state is a bit of a mess mainly because I started writing it without a clear idea of how it should look like. Basically a model represents a composite network setup and aims to make it easy to configure common network setups. In the future may be the network functionality should be decoupled from the runtime like Docker currently does.

Supported interface types

  • veth: it's a normal veth pair

Network Models

To activate a model add a model object to the config. When a module config is present, all interfaces are related to the module. Only one module is allowed per config/box:

"model": {
   "type": "model_name",
   "param1": "val1",
   ...
}

Supported models

  • Bridge: connects a box to an external network by creating and attaching a veth master to a given bridge interface and moving the peer to the box NS. Example:
"model": {
   "type": "bridge",
   "bridge_name": "docker0"
}

Config file

Simple config without model

{
  "loopback_name": "lo",
  "interfaces": [
    {
      "type": "veth",
      "name": "eth1",
      "peer_name": "eth2",
      "ip": "10.0.0.1/30",
      "peer_ip":  "10.0.0.2/30",
      "routes": [
        {
          "subnet": "0.0.0.0/0",
          "gateway": "10.0.0.1"
        }
      ]
    }
  ],
  "dns": {
    "nameservers": [
      "10.0.0.1"
    ],
    "domain": "lambda1",
    "search": [
      "lambda1",
      "lambda.local"
    ]
  }
}

With model bridge

{
  "loopback_name": "lo",
  "model": {
    "type": "bridge",
    "bridge_name": "docker0"
  },
  "interfaces": [
    {
      "type": "veth",
      "name": "eth1",
      "peer_name": "eth2",
      "ip": "0.0.0.0/0",
      "peer_ip":  "172.17.0.6/28",
      "routes": [
        {
          "subnet": "0.0.0.0/0",
          "gateway": "172.17.0.1"
        }
      ]
    }
  ],
  "dns": {
    "nameservers": [
      "8.8.8.8"
    ],
    "domain": "lambda1",
    "search": [
      "lambda1",
      "lambda.local"
    ]
  }
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrModelNotDefined = errors.New("network model not defined")
View Source
var ErrTypeNotDefined = errors.New("interface type not defined")

Functions

func ConfigFromRawConfig

func ConfigFromRawConfig(rawConf map[string]interface{}, dst interface{}) error

func ExecuteOnNs

func ExecuteOnNs(pidns int, f func()) (err error)

func ModelFromConfig

func ModelFromConfig(conf map[string]interface{}) (string, error)

func TypeFromConfig

func TypeFromConfig(conf map[string]interface{}) (string, error)

Types

type Bridger

type Bridger interface {
}

func NewBridgeModel

func NewBridgeModel(brName string, nsPID int, ifsConfig []map[string]interface{}) (Bridger, error)

type DNSConf

type DNSConf struct {
	Nameservers []string `json:"nameservers,omitempty"`
	Domain      string   `json:"domain,omitempty"`
	Search      []string `json:"search,omitempty"`
}

DNSConf resolvers config.

type IFacer

type IFacer interface {
	Down() error
	Up() error
	Type() string
	SetMaster(master netlink.Link) error
}

type Model

type Model struct {
	Type string `json:"type"`
}

type ModelBridge

type ModelBridge struct {
	BrName string `json:"bridge_name"`
}

type NetConf

type NetConf struct {
	Model        map[string]interface{}   `json:"model,omitempty"`
	LoopbackName string                   `json:"loopback_name,omitempty"`
	Interfaces   []map[string]interface{} `json:"interfaces,omitempty"`
	DNS          DNSConf                  `json:"dns,omitempty"`
}

NetConf holds config for interfaces and DNS resolvers.

func Load

func Load(rd io.Reader) (*NetConf, error)

func LoadFromFile

func LoadFromFile(path string) (*NetConf, error)

type Route

type Route struct {
	Subnet  string `json:"subnet"`
	Gateway string `json:"gateway"`
}

Route config where Subnet must be in CIDR format.

type VethConf

type VethConf struct {
	Type     string  `json:"type"`
	Name     string  `json:"name"`
	PeerName string  `json:"peer_name"`
	Ip       string  `json:"ip"`
	PeerIp   string  `json:"peer_ip"`
	Routes   []Route `json:"routes,omitempty"`
}

VethConf holds a config of a single veth pair. Ip and PeerIp holds a CIDR format IP.

type Vether

type Vether interface {
	IFacer
	PeerDown() error
	PeerUp() error
	SetAddr(addr net.IPNet) error
	SetPeerAddr(addr net.IPNet) error
	SetPeerNsByPid(nspid int) error
	SetRoutes(routes []Route) error
}

func AttachVeth

func AttachVeth(cfg VethConf, nsPID int) (Vether, error)

func NewVeth

func NewVeth(name, peerName string) (Vether, error)

func VethFromConfig

func VethFromConfig(conf VethConf, nsPID int) (Vether, error)

Jump to

Keyboard shortcuts

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