mw

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package mw is a generated GoMock package.

Index

Constants

View Source
const (
	V4AddrLen = 4
	V6AddrLen = 16
)

IP address lengths (bytes).

View Source
const EthAddrLen = 6
View Source
const EthFrameLenMax = 1514
View Source
const EthFrameLenMin = 60
View Source
const EthHdrLen = 14
View Source
const EthPayloadLenMax = EthFrameLenMax - EthHdrLen
View Source
const EthPayloadLenMin = EthFrameLenMin - EthHdrLen
View Source
const LoopbackBroadcast = "127.255.255.255"
View Source
const LoopbackIpAddr = "127.0.0.1"
View Source
const LoopbackNetmask = "255.0.0.0"
View Source
const LoopbackNetwork = "127.0.0.0"

Variables

View Source
var (
	V4Any       = V4(0, 0, 0, 0)
	V4Broadcast = V4(255, 255, 255, 255)
)

IP address expressions

View Source
var ArpRxCh chan *ArpRxMessage
View Source
var ArpTxCh chan *ArpTxMessage
View Source
var EthAny = EthAddr{0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
View Source
var EthBroadcast = EthAddr{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
View Source
var EthRxCh chan *EthMessage // channel for receiving packets
View Source
var EthTxCh chan *EthMessage // channel for sending packets
View Source
var IcmpDeadLetterQueue chan *IcmpQueueEntry
View Source
var IcmpRxCh chan *IcmpRxMessage
View Source
var IcmpTxCh chan *IcmpTxMessage
View Source
var IpRxCh chan *EthMessage
View Source
var IpTxCh chan *IpMessage
View Source
var TcpRxCh chan *TcpRxMessage
View Source
var TcpTxCh chan *TcpTxMessage

Functions

func Checksum

func Checksum(b []byte, init uint32) uint16

func RandU16 added in v0.4.0

func RandU16() uint16

func RandU32 added in v0.5.0

func RandU32() uint32

func RandU8 added in v0.4.0

func RandU8() uint8

func WriteFrame

func WriteFrame(fd int, dst EthAddr, src EthAddr, typ EthType, payload []byte) psErr.E

Types

type AddrFamily

type AddrFamily int

AddrFamily is IP address family.

const (
	V4AddrFamily AddrFamily = syscall.AF_INET
	V6AddrFamily AddrFamily = syscall.AF_INET6
)

IP address family

func (AddrFamily) String

func (v AddrFamily) String() string

type ArpRxMessage

type ArpRxMessage struct {
	Packet []byte
	Dev    IDevice
}

type ArpTxMessage

type ArpTxMessage struct {
	Iface *Iface
	IP    IP
}

type DevFlag

type DevFlag uint16
const BroadcastFlag DevFlag = 0x0020
const LoopbackFlag DevFlag = 0x0010
const NeedArpFlag DevFlag = 0x0100
const UpFlag DevFlag = 0x0001

type DevType

type DevType int
const (
	EthernetDevice DevType = iota
	LoopbackDevice
	NullDevice
)

func (DevType) String

func (v DevType) String() string

type Device

type Device struct {
	Type_ DevType
	Name_ string
	Addr_ EthAddr
	Flag_ DevFlag
	MTU_  uint16
	Priv_ Privilege
}

func (*Device) Addr

func (p *Device) Addr() EthAddr

func (*Device) Down

func (p *Device) Down()

func (*Device) Equal

func (p *Device) Equal(pp IDevice) bool

func (*Device) Flag

func (p *Device) Flag() DevFlag

func (*Device) IsUp

func (p *Device) IsUp() bool

func (*Device) MTU

func (p *Device) MTU() uint16

func (*Device) Name

func (p *Device) Name() string

func (*Device) Priv

func (p *Device) Priv() Privilege

func (*Device) Type

func (p *Device) Type() DevType

func (*Device) Up

func (p *Device) Up()

type EthAddr

type EthAddr [EthAddrLen]byte

func (EthAddr) Equal

func (v EthAddr) Equal(vv EthAddr) bool

func (EthAddr) String

func (v EthAddr) String() string

type EthHdr

type EthHdr struct {
	Dst  EthAddr
	Src  EthAddr
	Type EthType
}

type EthMessage

type EthMessage struct {
	Type    EthType
	Content []byte
	Dev     IDevice
}

func ReadFrame

func ReadFrame(fd int, addr EthAddr) (*EthMessage, psErr.E)

type EthType

type EthType uint16
const (
	EtARP  EthType = 0x0806
	EtIPV4 EthType = 0x0800
	EtIPV6 EthType = 0x86dd
)

func (EthType) String

func (v EthType) String() string

type IDevice

type IDevice interface {
	Open() psErr.E
	Close() psErr.E
	Poll() psErr.E
	Transmit(dst EthAddr, payload []byte, typ EthType) psErr.E
	Up()
	Down()
	Equal(dev IDevice) bool
	IsUp() bool
	Type() DevType
	Name() string
	Addr() EthAddr
	Flag() DevFlag
	MTU() uint16
	Priv() Privilege
}

type IP

type IP []byte

An IP is a single IP address.

func LongestIP

func LongestIP(ip1 IP, ip2 IP) IP

func ParseIP

func ParseIP(s string) IP

ParseIP parses string as IPv4 or IPv6 address by detecting its format.

func V4

func V4(a, b, c, d byte) IP

V4 creates IP from bytes. TODO: use IPv4-mapped address above

func V4FromByte added in v0.5.0

func V4FromByte(b [V4AddrLen]byte) IP

func (IP) Equal

func (v IP) Equal(x IP) bool

func (IP) EqualV4

func (v IP) EqualV4(v4 [V4AddrLen]byte) bool

func (IP) Mask

func (v IP) Mask(mask IP) IP

func (IP) String

func (v IP) String() string

String returns the string form of IP.

func (IP) ToV4

func (v IP) ToV4() (ip [V4AddrLen]byte)

ToV4 converts IP to 4 bytes representation.

type IcmpQueueEntry added in v0.4.0

type IcmpQueueEntry struct {
	Payload []byte
}

type IcmpRxMessage

type IcmpRxMessage struct {
	Payload []byte
	Dst     [V4AddrLen]byte
	Src     [V4AddrLen]byte
	Dev     IDevice
}

type IcmpTxMessage

type IcmpTxMessage struct {
	Type    uint8
	Code    uint8
	Content uint32
	Payload []byte
	Src     IP
	Dst     IP
}

type Iface

type Iface struct {
	Family    AddrFamily
	Unicast   IP
	Netmask   IP
	Broadcast IP
	Dev       IDevice
}

An Iface is a single iface.

type IpHdr

type IpHdr struct {
	VHL      uint8
	TOS      uint8
	TotalLen uint16
	ID       uint16
	Offset   uint16
	TTL      uint8
	Protocol ProtocolNumber
	Checksum uint16
	Src      [V4AddrLen]byte
	Dst      [V4AddrLen]byte
	Options  [0]byte
}

IpHdr is an internet protocol header

type IpMessage

type IpMessage struct {
	ProtoNum ProtocolNumber
	Packet   []byte
	Dst      [V4AddrLen]byte
	Src      [V4AddrLen]byte
}

type MockIDevice

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

MockIDevice is a mock of IDevice interface.

func NewMockIDevice

func NewMockIDevice(ctrl *gomock.Controller) *MockIDevice

NewMockIDevice creates a new mock instance.

func (*MockIDevice) Addr

func (m *MockIDevice) Addr() EthAddr

Addr mocks base method.

func (*MockIDevice) Close

func (m *MockIDevice) Close() error.E

Close mocks base method.

func (*MockIDevice) Down

func (m *MockIDevice) Down()

Down mocks base method.

func (*MockIDevice) EXPECT

func (m *MockIDevice) EXPECT() *MockIDeviceMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockIDevice) Equal

func (m *MockIDevice) Equal(dev IDevice) bool

Equal mocks base method.

func (*MockIDevice) Flag

func (m *MockIDevice) Flag() DevFlag

Flag mocks base method.

func (*MockIDevice) IsUp

func (m *MockIDevice) IsUp() bool

IsUp mocks base method.

func (*MockIDevice) MTU

func (m *MockIDevice) MTU() uint16

MTU mocks base method.

func (*MockIDevice) Name

func (m *MockIDevice) Name() string

Name mocks base method.

func (*MockIDevice) Open

func (m *MockIDevice) Open() error.E

Open mocks base method.

func (*MockIDevice) Poll

func (m *MockIDevice) Poll() error.E

Poll mocks base method.

func (*MockIDevice) Priv

func (m *MockIDevice) Priv() Privilege

Priv mocks base method.

func (*MockIDevice) Transmit

func (m *MockIDevice) Transmit(dst EthAddr, payload []byte, typ EthType) error.E

Transmit mocks base method.

func (*MockIDevice) Type

func (m *MockIDevice) Type() DevType

Type mocks base method.

func (*MockIDevice) Up

func (m *MockIDevice) Up()

Up mocks base method.

type MockIDeviceMockRecorder

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

MockIDeviceMockRecorder is the mock recorder for MockIDevice.

func (*MockIDeviceMockRecorder) Addr

func (mr *MockIDeviceMockRecorder) Addr() *gomock.Call

Addr indicates an expected call of Addr.

func (*MockIDeviceMockRecorder) Close

func (mr *MockIDeviceMockRecorder) Close() *gomock.Call

Close indicates an expected call of Close.

func (*MockIDeviceMockRecorder) Down

func (mr *MockIDeviceMockRecorder) Down() *gomock.Call

Down indicates an expected call of Down.

func (*MockIDeviceMockRecorder) Equal

func (mr *MockIDeviceMockRecorder) Equal(dev interface{}) *gomock.Call

Equal indicates an expected call of Equal.

func (*MockIDeviceMockRecorder) Flag

func (mr *MockIDeviceMockRecorder) Flag() *gomock.Call

Flag indicates an expected call of Flag.

func (*MockIDeviceMockRecorder) IsUp

func (mr *MockIDeviceMockRecorder) IsUp() *gomock.Call

IsUp indicates an expected call of IsUp.

func (*MockIDeviceMockRecorder) MTU

func (mr *MockIDeviceMockRecorder) MTU() *gomock.Call

MTU indicates an expected call of MTU.

func (*MockIDeviceMockRecorder) Name

func (mr *MockIDeviceMockRecorder) Name() *gomock.Call

Name indicates an expected call of Name.

func (*MockIDeviceMockRecorder) Open

func (mr *MockIDeviceMockRecorder) Open() *gomock.Call

Open indicates an expected call of Open.

func (*MockIDeviceMockRecorder) Poll

func (mr *MockIDeviceMockRecorder) Poll() *gomock.Call

Poll indicates an expected call of Poll.

func (*MockIDeviceMockRecorder) Priv

func (mr *MockIDeviceMockRecorder) Priv() *gomock.Call

Priv indicates an expected call of Priv.

func (*MockIDeviceMockRecorder) Transmit

func (mr *MockIDeviceMockRecorder) Transmit(dst, payload, typ interface{}) *gomock.Call

Transmit indicates an expected call of Transmit.

func (*MockIDeviceMockRecorder) Type

func (mr *MockIDeviceMockRecorder) Type() *gomock.Call

Type indicates an expected call of Type.

func (*MockIDeviceMockRecorder) Up

Up indicates an expected call of Up.

type Privilege

type Privilege struct {
	Name string
	FD   int
}

type ProtocolNumber

type ProtocolNumber uint8

ProtocolNumber is assigned internet protocol number

const (
	PnICMP ProtocolNumber = 1
	PnTCP  ProtocolNumber = 6
	PnUDP  ProtocolNumber = 17
)

func (ProtocolNumber) String

func (v ProtocolNumber) String() string

type TcpRxMessage added in v0.5.0

type TcpRxMessage struct {
	ProtoNum   uint8
	RawSegment []byte
	Dst        [V4AddrLen]byte
	Src        [V4AddrLen]byte
	Iface      *Iface
}

type TcpTxMessage added in v0.5.0

type TcpTxMessage struct{}

type V4Addr

type V4Addr [V4AddrLen]byte

func (V4Addr) String

func (v V4Addr) String() string

Jump to

Keyboard shortcuts

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