network

package
v0.0.0-...-813d602 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: GPL-3.0 Imports: 13 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"
	CMark    = "MARK"
	CCT      = "CT"
	CNoTrk   = "NOTRACK"
	CSnat    = "SNAT"
	CTcpMss  = "TCPMSS"
)
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 AddrAdd

func AddrAdd(name, addr string, opts ...string) ([]byte, error)

func AddrDel

func AddrDel(name, addr string) ([]byte, error)

func AddrShow

func AddrShow(name string) []string

func GenTable

func GenTable() int

func GetName

func GetName(name string) string

func GetPair

func GetPair(name string) (string, string)

func IPTableInit

func IPTableInit()

func LinkAdd

func LinkAdd(name string, opts ...string) ([]byte, error)

func LinkDel

func LinkDel(name string, opts ...string) ([]byte, error)

func LinkDown

func LinkDown(name string) ([]byte, error)

func LinkSet

func LinkSet(name string, opts ...string) ([]byte, error)

func LinkUp

func LinkUp(name string) ([]byte, error)

func LookupIP

func LookupIP(name string) string

func RouteAdd

func RouteAdd(name, prefix, nexthop string, opts ...string) ([]byte, error)

func RouteDel

func RouteDel(name, prefix, nexthop string, opts ...string) ([]byte, error)

func RouteShow

func RouteShow(name string) []string

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
	L3Name() string
	SetMtu(mtu int) error
}

func NewBridger

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

type DeviceStats

type DeviceStats struct {
	Send    uint64 `json:"send"`
	Recv    uint64 `json:"recv"`
	Drop    uint64 `json:"drop"`
	Mac     string `json:"mac"`
	Address uint64 `json:"address"`
	Mtu     int    `json:"mtu"`
}

func GetDevStats

func GetDevStats(name string) DeviceStats

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) AddRuleX

func (ch *FireWallChain) AddRuleX(rule IPRule) error

func (*FireWallChain) Cancel

func (ch *FireWallChain) Cancel()

func (*FireWallChain) Chain

func (ch *FireWallChain) Chain() IPChain

func (*FireWallChain) DelRuleX

func (ch *FireWallChain) DelRuleX(rule IPRule) error

func (*FireWallChain) Flush

func (ch *FireWallChain) Flush()

func (*FireWallChain) Install

func (ch *FireWallChain) Install()

func (*FireWallChain) Jump

func (ch *FireWallChain) Jump() IPRule

func (*FireWallChain) Prepare

func (ch *FireWallChain) Prepare()

type FireWallFilter

type FireWallFilter struct {
	In  *FireWallChain
	Out *FireWallChain
	For *FireWallChain
	// 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 FireWallMangle

type FireWallMangle struct {
	Pre  *FireWallChain
	In   *FireWallChain
	For  *FireWallChain
	Out  *FireWallChain
	Post *FireWallChain
	// 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
	// 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
	// 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 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
	Limit      string
	LimitBurst string
	SetMss     int
	Mark       uint32
	SetMark    uint32
	Zone       uint32
	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

func (IPRule) Utoa

func (ru IPRule) Utoa(value uint32) 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 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 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) Stats

func (t *KernelTap) Stats() DeviceStats

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) L3Name

func (b *LinuxBridge) L3Name() 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) Plugin

func (b *LinuxBridge) Plugin(addr *nl.Addr) error

func (*LinuxBridge) SetMtu

func (b *LinuxBridge) SetMtu(mtu int) error

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

func (*LinuxBridge) Unplugin

func (b *LinuxBridge) Unplugin() error

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
	Stats() DeviceStats
}

func NewTaper

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

type VRF

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

func NewVRF

func NewVRF(name string, table int) *VRF

func (*VRF) AddSlave

func (v *VRF) AddSlave(name string) error

func (*VRF) DelSlave

func (v *VRF) DelSlave(name string) error

func (*VRF) Down

func (v *VRF) Down() error
func (v *VRF) Link() nl.Link

func (*VRF) Name

func (v *VRF) Name() string

func (*VRF) Table

func (v *VRF) Table() int

func (*VRF) Up

func (v *VRF) Up() error

type VRFs

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

func (*VRFs) Add

func (s *VRFs) Add(name string, obj *VRF)

func (*VRFs) Get

func (s *VRFs) Get(name string) *VRF

Jump to

Keyboard shortcuts

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