network

package
v0.0.0-...-04092ee Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2023 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProviderVir = "virtual"
	ProviderKer = "kernel"
	ProviderLin = "linux"
)
View Source
const (
	OLCInput   = "XTT_in"
	OLCForward = "XTT_for"
	OLCOutput  = "XTT_out"
	OLCPre     = "XTT_pre"
	OLCPost    = "XTT_pos"
)
View Source
const (
	TNat     = "nat"
	TRaw     = "raw"
	TMangle  = "mangle"
	TFilter  = "filter"
	CInput   = "INPUT"
	CForward = "FORWARD"
	COutput  = "OUTPUT"
	CPost    = "POSTROUTING"
	CPre     = "PREROUTING"
	CMasq    = "MASQUERADE"
	CNoTrk   = "NOTRACK"
	CSnat    = "SNAT"
)
View Source
const (
	UsClose = uint(0x02)
	UsUp    = uint(0x04)
	TUN     = 0x01
	TAP     = 0x02
)

Variables

View Source
var Bridges = &bridger{}
View Source
var Taps = &tapers{}

Functions

func IptableInit

func IptableInit()

func WaterNew

func WaterNew(c TapConfig) (*water.Interface, error)

Types

type BrCtl

type BrCtl struct {
	Name string
	Path string
	Mtu  int
}

func NewBrCtl

func NewBrCtl(name string, mtu int) (b *BrCtl)

func (*BrCtl) AddPort

func (b *BrCtl) AddPort(port string) error

func (*BrCtl) CallIptables

func (b *BrCtl) CallIptables(value int) error

func (*BrCtl) DelPort

func (b *BrCtl) DelPort(port string) error

func (*BrCtl) Delay

func (b *BrCtl) Delay(delay int) error

func (*BrCtl) Has

func (b *BrCtl) Has() bool

func (*BrCtl) Stp

func (b *BrCtl) Stp(on bool) error

func (*BrCtl) SysPath

func (b *BrCtl) SysPath(fun string) string

type BrPort

type BrPort struct {
	Name string
	Path string
}

func NewBrPort

func NewBrPort(name string) (p *BrPort)

func (*BrPort) Cost

func (p *BrPort) Cost(cost int) error

func (*BrPort) SysPath

func (p *BrPort) SysPath(fun string) string

type Bridger

type Bridger interface {
	Type() string
	Name() string
	Open(addr string)
	Close() error
	AddSlave(name string) error
	DelSlave(name string) error
	ListSlave() <-chan Taper
	Mtu() int
	Stp(enable bool) error
	Delay(value int) error
	Kernel() string // name in kernel.
	ListMac() <-chan *MacFdb
	String() string
	Stats() DeviceStats
	CallIptables(value int) error
}

func NewBridger

func NewBridger(provider, name string, ifMtu int) Bridger

type DeviceStats

type DeviceStats struct {
	Send int64 `json:"send"`
	Recv int64 `json:"recv"`
	Drop int64 `json:"drop"`
}

type FireWallChain

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

func NewFireWallChain

func NewFireWallChain(name, table, parent string) *FireWallChain

func (*FireWallChain) AddRule

func (ch *FireWallChain) AddRule(rule IpRule)

func (*FireWallChain) Cancel

func (ch *FireWallChain) Cancel()

func (*FireWallChain) Chain

func (ch *FireWallChain) Chain() IpChain

func (*FireWallChain) Install

func (ch *FireWallChain) Install()

type FireWallFilter

type FireWallFilter struct {
	In   *FireWallChain
	Out  *FireWallChain
	For  *FireWallChain
	Jump *FireWallJump
	// contains filtered or unexported fields
}

func NewFireWallFilter

func NewFireWallFilter(name string) *FireWallFilter

func (*FireWallFilter) Cancel

func (f *FireWallFilter) Cancel()

func (*FireWallFilter) Install

func (f *FireWallFilter) Install()

type FireWallGlobal

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

func NewFireWallGlobal

func NewFireWallGlobal(flows []config.FlowRule) *FireWallGlobal

func (*FireWallGlobal) AddChain

func (f *FireWallGlobal) AddChain(chain IpChain)

func (*FireWallGlobal) AddRule

func (f *FireWallGlobal) AddRule(rule IpRule)

func (*FireWallGlobal) CancelRule

func (f *FireWallGlobal) CancelRule(rule IpRule) error

func (*FireWallGlobal) Initialize

func (f *FireWallGlobal) Initialize()

func (*FireWallGlobal) InstallRule

func (f *FireWallGlobal) InstallRule(rule IpRule) error

func (*FireWallGlobal) Refresh

func (f *FireWallGlobal) Refresh()

func (*FireWallGlobal) Start

func (f *FireWallGlobal) Start()

func (*FireWallGlobal) Stop

func (f *FireWallGlobal) Stop()

type FireWallJump

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

func (*FireWallJump) Cancel

func (j *FireWallJump) Cancel()

func (*FireWallJump) Install

func (j *FireWallJump) Install(ch IpChain)

type FireWallMangle

type FireWallMangle struct {
	Pre  *FireWallChain
	In   *FireWallChain
	For  *FireWallChain
	Out  *FireWallChain
	Post *FireWallChain
	Jump *FireWallJump
	// contains filtered or unexported fields
}

func NewFireWallMangle

func NewFireWallMangle(name string) *FireWallMangle

func (*FireWallMangle) Cancel

func (m *FireWallMangle) Cancel()

func (*FireWallMangle) Install

func (m *FireWallMangle) Install()

type FireWallNAT

type FireWallNAT struct {
	Pre  *FireWallChain
	In   *FireWallChain
	Out  *FireWallChain
	Post *FireWallChain
	Jump *FireWallJump
	// contains filtered or unexported fields
}

func NewFireWallNAT

func NewFireWallNAT(name string) *FireWallNAT

func (*FireWallNAT) Cancel

func (n *FireWallNAT) Cancel()

func (*FireWallNAT) Install

func (n *FireWallNAT) Install()

type FireWallNATPre

type FireWallNATPre struct {
	*FireWallChain
}

func (*FireWallNATPre) Chain

func (ch *FireWallNATPre) Chain() IpChain

type FireWallRaw

type FireWallRaw struct {
	Pre  *FireWallChain
	Out  *FireWallChain
	Jump *FireWallJump
	// contains filtered or unexported fields
}

func NewFireWallRaw

func NewFireWallRaw(name string) *FireWallRaw

func (*FireWallRaw) Cancel

func (r *FireWallRaw) Cancel()

func (*FireWallRaw) Install

func (r *FireWallRaw) Install()

type FireWallTable

type FireWallTable struct {
	Filter *FireWallFilter
	Nat    *FireWallNAT
	Mangle *FireWallMangle
	Raw    *FireWallRaw
}

func NewFireWallTable

func NewFireWallTable(name string) *FireWallTable

func (*FireWallTable) Start

func (t *FireWallTable) Start()

func (*FireWallTable) Stop

func (t *FireWallTable) Stop()

type Framer

type Framer struct {
	Data   []byte
	Source Taper
	Output Taper
}

type IPSet

type IPSet struct {
	Name string
	Type string // hash:net, hash:ip
	Sudo bool
}

func NewIPSet

func NewIPSet(name, method string) *IPSet

func (*IPSet) Add

func (i *IPSet) Add(value string) (string, error)

func (*IPSet) Clear

func (i *IPSet) Clear() (string, error)

func (*IPSet) Create

func (i *IPSet) Create() (string, error)

func (*IPSet) Del

func (i *IPSet) Del(value string) (string, error)

func (*IPSet) Destroy

func (i *IPSet) Destroy() (string, error)

func (*IPSet) Flush

func (i *IPSet) Flush() (string, error)

type IpChain

type IpChain struct {
	Table string
	Name  string
	From  string
}

func (IpChain) Eq

func (ch IpChain) Eq(obj IpChain) bool

func (IpChain) Opr

func (ch IpChain) Opr(opr string) ([]byte, error)

type IpChains

type IpChains []IpChain

func (IpChains) Add

func (chains IpChains) Add(obj IpChain) IpChains

func (IpChains) Pop

func (chains IpChains) Pop(obj IpChain) IpChains

type IpRule

type IpRule struct {
	Table     string
	Chain     string
	Source    string
	SrcSet    string
	ToSource  string
	NoSource  string
	NoSrcSet  string
	Dest      string
	DestSet   string
	ToDest    string
	NoDest    string
	NoDestSet string
	Proto     string
	DstPort   string
	SrcPort   string
	Input     string
	Output    string
	Comment   string
	Jump      string
	SetMss    int
	Order     string
	Match     string
	CtState   string
	TcpFlag   []string
}

func (IpRule) Args

func (ru IpRule) Args() []string

func (IpRule) Eq

func (ru IpRule) Eq(obj IpRule) bool

func (IpRule) Exist

func (ru IpRule) Exist() bool

func (IpRule) Itoa

func (ru IpRule) Itoa(value int) string

func (IpRule) Opr

func (ru IpRule) Opr(opr string) ([]byte, error)

func (IpRule) String

func (ru IpRule) String() string

type IpRules

type IpRules []IpRule

func (IpRules) Add

func (rules IpRules) Add(obj IpRule) IpRules

func (IpRules) Has

func (rules IpRules) Has(rule IpRule) bool

func (IpRules) Remove

func (rules IpRules) Remove(obj IpRule) IpRules

type KernelTap

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

func NewKernelTap

func NewKernelTap(tenant string, c TapConfig) (*KernelTap, error)

func (*KernelTap) Close

func (t *KernelTap) Close() error

func (*KernelTap) Down

func (t *KernelTap) Down()

func (*KernelTap) Has

func (t *KernelTap) Has(v uint) bool

func (*KernelTap) IsTun

func (t *KernelTap) IsTun() bool

func (*KernelTap) Master

func (t *KernelTap) Master() Bridger

func (*KernelTap) Mtu

func (t *KernelTap) Mtu() int

func (*KernelTap) Name

func (t *KernelTap) Name() string

func (*KernelTap) Read

func (t *KernelTap) Read(p []byte) (int, error)

func (*KernelTap) Recv

func (t *KernelTap) Recv(p []byte) (int, error)

func (*KernelTap) Send

func (t *KernelTap) Send(p []byte) (int, error)

func (*KernelTap) SetMaster

func (t *KernelTap) SetMaster(dev Bridger) error

func (*KernelTap) String

func (t *KernelTap) String() string

func (*KernelTap) Tenant

func (t *KernelTap) Tenant() string

func (*KernelTap) Type

func (t *KernelTap) Type() string

func (*KernelTap) Up

func (t *KernelTap) Up()

func (*KernelTap) Write

func (t *KernelTap) Write(p []byte) (int, error)

type LinuxBridge

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

func NewLinuxBridge

func NewLinuxBridge(name string, mtu int) *LinuxBridge

func (*LinuxBridge) AddSlave

func (b *LinuxBridge) AddSlave(name string) error

func (*LinuxBridge) CallIptables

func (b *LinuxBridge) CallIptables(value int) error

func (*LinuxBridge) Close

func (b *LinuxBridge) Close() error

func (*LinuxBridge) DelSlave

func (b *LinuxBridge) DelSlave(name string) error

func (*LinuxBridge) Delay

func (b *LinuxBridge) Delay(value int) error

func (*LinuxBridge) Kernel

func (b *LinuxBridge) Kernel() string

func (*LinuxBridge) ListMac

func (b *LinuxBridge) ListMac() <-chan *MacFdb

func (*LinuxBridge) ListSlave

func (b *LinuxBridge) ListSlave() <-chan Taper

func (*LinuxBridge) Mtu

func (b *LinuxBridge) Mtu() int

func (*LinuxBridge) Name

func (b *LinuxBridge) Name() string

func (*LinuxBridge) Open

func (b *LinuxBridge) Open(addr string)

func (*LinuxBridge) Stats

func (b *LinuxBridge) Stats() DeviceStats

func (*LinuxBridge) Stp

func (b *LinuxBridge) Stp(enable bool) error

func (*LinuxBridge) String

func (b *LinuxBridge) String() string

func (*LinuxBridge) Type

func (b *LinuxBridge) Type() string

type MacFdb

type MacFdb struct {
	Address []byte
	Device  Taper
	Uptime  int64
	NewTime int64
}

type TapConfig

type TapConfig struct {
	Provider string
	Type     int
	Network  string
	Name     string
	VirBuf   int
	KernBuf  int
	Mtu      int
}

type Taper

type Taper interface {
	Type() string
	IsTun() bool
	Name() string
	Read([]byte) (int, error)  // read data from kernel to user space
	Write([]byte) (int, error) // write data from user space to kernel
	Send([]byte) (int, error)  // send data from virtual bridge to kernel
	Recv([]byte) (int, error)  // recv data from kernel to virtual bridge
	Close() error
	Master() Bridger
	SetMaster(dev Bridger) error
	Up()
	Down()
	Tenant() string
	Mtu() int
	String() string
	Has(v uint) bool
}

func NewTaper

func NewTaper(tenant string, c TapConfig) (Taper, error)

type VirtualBridge

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

func NewVirtualBridge

func NewVirtualBridge(name string, mtu int) *VirtualBridge

func (*VirtualBridge) AddMac

func (b *VirtualBridge) AddMac(mac string, fdb *MacFdb)

func (*VirtualBridge) AddSlave

func (b *VirtualBridge) AddSlave(name string) error

func (*VirtualBridge) CallIptables

func (b *VirtualBridge) CallIptables(value int) error

func (*VirtualBridge) Close

func (b *VirtualBridge) Close() error

func (*VirtualBridge) DelSlave

func (b *VirtualBridge) DelSlave(name string) error

func (*VirtualBridge) Delay

func (b *VirtualBridge) Delay(value int) error

func (*VirtualBridge) Eth2Str

func (b *VirtualBridge) Eth2Str(addr []byte) string

func (*VirtualBridge) Expire

func (b *VirtualBridge) Expire() error

func (*VirtualBridge) Flood

func (b *VirtualBridge) Flood(m *Framer) error

func (*VirtualBridge) Forward

func (b *VirtualBridge) Forward(m *Framer) error

func (*VirtualBridge) GetMac

func (b *VirtualBridge) GetMac(mac string) *MacFdb

func (*VirtualBridge) Input

func (b *VirtualBridge) Input(m *Framer) error

func (*VirtualBridge) Kernel

func (b *VirtualBridge) Kernel() string

func (*VirtualBridge) Learn

func (b *VirtualBridge) Learn(m *Framer)

func (*VirtualBridge) ListMac

func (b *VirtualBridge) ListMac() <-chan *MacFdb

func (*VirtualBridge) ListSlave

func (b *VirtualBridge) ListSlave() <-chan Taper

func (*VirtualBridge) Mtu

func (b *VirtualBridge) Mtu() int

func (*VirtualBridge) Name

func (b *VirtualBridge) Name() string

func (*VirtualBridge) Open

func (b *VirtualBridge) Open(addr string)

func (*VirtualBridge) Start

func (b *VirtualBridge) Start()

func (*VirtualBridge) Stats

func (b *VirtualBridge) Stats() DeviceStats

func (*VirtualBridge) Stp

func (b *VirtualBridge) Stp(enable bool) error

func (*VirtualBridge) String

func (b *VirtualBridge) String() string

func (*VirtualBridge) Type

func (b *VirtualBridge) Type() string

func (*VirtualBridge) UniCast

func (b *VirtualBridge) UniCast(m *Framer) error

func (*VirtualBridge) UpdateMac

func (b *VirtualBridge) UpdateMac(mac string, device Taper)

type VirtualTap

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

func NewVirtualTap

func NewVirtualTap(tenant string, c TapConfig) (*VirtualTap, error)

func (*VirtualTap) Close

func (t *VirtualTap) Close() error

func (*VirtualTap) Down

func (t *VirtualTap) Down()

func (*VirtualTap) Has

func (t *VirtualTap) Has(v uint) bool

func (*VirtualTap) IsTun

func (t *VirtualTap) IsTun() bool

func (*VirtualTap) Master

func (t *VirtualTap) Master() Bridger

func (*VirtualTap) Mtu

func (t *VirtualTap) Mtu() int

func (*VirtualTap) Name

func (t *VirtualTap) Name() string

func (*VirtualTap) Read

func (t *VirtualTap) Read(p []byte) (int, error)

func (*VirtualTap) Recv

func (t *VirtualTap) Recv(p []byte) (int, error)

func (*VirtualTap) Send

func (t *VirtualTap) Send(p []byte) (int, error)

func (*VirtualTap) SetMaster

func (t *VirtualTap) SetMaster(dev Bridger) error

func (*VirtualTap) String

func (t *VirtualTap) String() string

func (*VirtualTap) Tenant

func (t *VirtualTap) Tenant() string

func (*VirtualTap) Type

func (t *VirtualTap) Type() string

func (*VirtualTap) Up

func (t *VirtualTap) Up()

func (*VirtualTap) Write

func (t *VirtualTap) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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