Documentation ¶
Overview ¶
This package provides a singleton bridge object that wraps openvswitch. It allows the programmatic creation and deletion of bridges and taps, packet captures, applying qos constraints, and adding tunnels and trunks.
It also tracks information about taps such as recent bandwidth stats and snoops on traffic to the identify IP addresses associated with them.
Index ¶
- Constants
- Variables
- func CheckOVS() error
- func DestroyBridge(name string) error
- func DestroyTap(name string) error
- type Bridge
- func (b *Bridge) AddTap(tap, mac string, lan int, host bool) error
- func (b *Bridge) AddTrunk(iface string) error
- func (b *Bridge) AddTunnel(typ TunnelType, remoteIP, key string) error
- func (b *Bridge) Capture(fname string, config ...CaptureConfig) (int, error)
- func (b *Bridge) CaptureTap(tap, fname string, config ...CaptureConfig) (int, error)
- func (b *Bridge) Config(s string) error
- func (b *Bridge) CreateContainerTap(tap, ns, mac string, vlan, index int) (string, error)
- func (b *Bridge) CreateHostTap(tap string, lan int) (string, error)
- func (b *Bridge) CreateMirror(src, dst string) error
- func (b *Bridge) CreateTap(mac string, vlan int) (string, error)
- func (b *Bridge) DestroyMirror(tap string) error
- func (b *Bridge) DestroyNetflow() error
- func (b *Bridge) DestroyTap(tap string) error
- func (b *Bridge) GetNetflow() (*gonetflow.Netflow, error)
- func (b *Bridge) GetQos(tap string) []QosOption
- func (b *Bridge) NewNetflow(timeout int) (*gonetflow.Netflow, error)
- func (b *Bridge) ReapTaps() error
- func (b *Bridge) RemoveQos(tap string) error
- func (b *Bridge) RemoveTap(tap string) error
- func (b *Bridge) RemoveTrunk(iface string) error
- func (b *Bridge) RemoveTunnel(iface string) error
- func (b *Bridge) SetNetflowTimeout(timeout int) error
- func (b *Bridge) StopCapture(id int) error
- func (b *Bridge) UpdateQos(tap string, op QosOption) error
- type BridgeInfo
- type Bridges
- func (b Bridges) BandwidthStats() (float64, float64)
- func (b Bridges) Destroy() error
- func (b Bridges) DestroyBridge(name string) error
- func (b Bridges) FindTap(t string) (Tap, error)
- func (b Bridges) Get(name string) (*Bridge, error)
- func (b Bridges) HostTaps() []Tap
- func (b Bridges) Info() []BridgeInfo
- func (b Bridges) Names() []string
- func (b Bridges) ReapTaps() error
- type CaptureConfig
- type QosOption
- type QosType
- type Tap
- type TunnelType
Constants ¶
const DefaultSnapLen = 1600
Variables ¶
var ErrNoNetflow = errors.New("bridge has no netflow object")
var ExternalDependencies = []string{
"ip",
"ovs-vsctl",
"ovs-ofctl",
"tc",
}
Functions ¶
func CheckOVS ¶
func CheckOVS() error
CheckOVS runs a simple openvswitch command to test whether openvswitch is running or not.
func DestroyBridge ¶
DestroyBridge deletes an `unmanaged` bridge. This can be used when cleaning up from a crash. See `Bride.Destroy` for managed bridges.
func DestroyTap ¶
DestroyTap destroys an `unmanaged` tap using the `ip` command. This can be used when cleaning up from a crash or when a tap is not connected to a bridges. See `Bridge.DestroyTap` for managed taps.
Types ¶
type Bridge ¶
type Bridge struct { Name string // contains filtered or unexported fields }
Bridge stores state about an openvswitch bridge including the taps, tunnels, trunks, and netflow.
func (*Bridge) AddTap ¶
AddTap adds an existing tap to the bridge. Can be used in conjunction with `Bridge.RemoveTap` to relocate tap to a different bridge or VLAN.
func (*Bridge) AddTunnel ¶
func (b *Bridge) AddTunnel(typ TunnelType, remoteIP, key string) error
AddTunnel adds a new vxlan or GRE tunnel to a bridge.
func (*Bridge) Capture ¶
func (b *Bridge) Capture(fname string, config ...CaptureConfig) (int, error)
Capture traffic from a bridge to fname. Only the first config is used, if there is more than one. Returns an ID which can be passed to RemoveCapture to stop the capture.
func (*Bridge) CaptureTap ¶
func (b *Bridge) CaptureTap(tap, fname string, config ...CaptureConfig) (int, error)
CaptureTap captures traffic for the specified tap to fname. Only the first config is used, if there is more than one. Returns an ID which can be passed to RemoveCapture to stop the capture.
func (*Bridge) CreateContainerTap ¶
CreateContainerTap creates a veth tap and adds it to the bridge. tap is the name of the tap, it will be automatically generated if unspecified. ns is the network namespace for the tap. mac is the MAC address to assign to the interface. vlan is the VLAN for the traffic. index is the veth interface number for the container.
func (*Bridge) CreateHostTap ¶
CreateHostTap creates and adds a host tap to a bridge. If a name is not provided, one will be automatically generated.
func (*Bridge) CreateMirror ¶
CreateMirror mirrors traffic. src is the tap to mirror, an empty src implies mirroring the entire bridge. dst is the tap to mirror to, which must already exist.
func (*Bridge) CreateTap ¶
CreateTap creates a new tap and adds it to the bridge. mac is the MAC address to assign to the interface. vlan is the VLAN for the traffic.
func (*Bridge) DestroyMirror ¶
func (*Bridge) DestroyNetflow ¶
DestroyNetflow destroys the active netflow.
func (*Bridge) DestroyTap ¶
DestroyTap removes a tap from the bridge and marks it as defunct. See `Bridge.ReapTaps` to clean up defunct taps. If the tap is a mirror, it cleans up the mirror too.
func (*Bridge) GetNetflow ¶
GetNetflow returns the active netflow for the bridge.
func (*Bridge) NewNetflow ¶
NewNetflow creates a new netflow for the bridge.
func (*Bridge) RemoveTap ¶
RemoveTap removes a tap from the bridge but doesn't remove the underlying device so that it may be added to another bridge. See `Bridge.AddTap`.
func (*Bridge) RemoveTrunk ¶
RemoveTrunk removes a trunk port from the bridge.
func (*Bridge) RemoveTunnel ¶
RemoveTunnel removes a tunnel from the bridge.
func (*Bridge) SetNetflowTimeout ¶
SetNetflowTimeout updates the timeout on the active netflow.
func (*Bridge) StopCapture ¶
type BridgeInfo ¶
type BridgeInfo struct { Name string PreExist bool VLANs []int Trunks []string Tunnels []string Mirrors []string Config map[string]string }
BridgeInfo is a summary of fields from a Bridge.
type Bridges ¶
type Bridges struct { Default string // Default bridge name when one isn't specified // contains filtered or unexported fields }
Bridges manages a collection of `Bridge` structs.
func NewBridges ¶
NewBridges creates a new Bridges using d as the default bridge name and f as the format string for the tap names (e.g. "mega_tap%v").
func (Bridges) BandwidthStats ¶
BandwidthStats computes the sum of the rates of MB received and transmitted across all taps on the given bridge.
func (Bridges) DestroyBridge ¶
DestroyBridge destroys a bridge by name, removing all of the taps, etc. associated with it.
func (Bridges) FindTap ¶
FindTap finds a non-defunct Tap with the specified name. This is non-deterministic if there are multiple taps with the same name.
func (Bridges) Info ¶
func (b Bridges) Info() []BridgeInfo
Info collects `BridgeInfo` for all managed bridges.
type CaptureConfig ¶
type CaptureConfig struct { // Filter is a BPF string to apply to all packets. See `man pcap-filter` // for the syntax and semantics. Filter string // SnapLen controls how many bytes to capture for each packet. According to // `man pcap`, 65535 should be sufficient to capture full packets on most // networks. If you only need headers, you can set it much lower (i.e. // 200). When zero, we use DefaultSnapLen. SnapLen uint32 }
type Tap ¶
type Tap struct { Name string // Name of the tap Bridge string // Bridge that the tap is connected to VLAN int // VLAN ID for the tap MAC string // MAC address Host bool // Set when created as a host tap (and, thus, promiscuous) Container bool // Set when created via CreateContainerTap Defunct bool // Set when Tap should be reaped IP4 string // Snooped IPv4 address IP6 string // Snooped IPv6 address // contains filtered or unexported fields }
Tap represents an interface that is attached to an openvswitch bridge.
func (Tap) BandwidthStats ¶
BandwidthStats computes the average rate of MB received and transmitted on the given tap over the 10 previous 5 second intervals. Returns the received and transmitted rates, in MBps.
type TunnelType ¶
type TunnelType int
TunnelType is used to specify the type of tunnel for `AddTunnel`.
const ( TunnelVXLAN TunnelType = iota TunnelGRE )
func (TunnelType) String ¶
func (t TunnelType) String() string