dufu

package module
v0.0.0-...-325fdcb Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2017 License: MIT Imports: 17 Imported by: 0

README

dufu

A Go userspace network stack based on dpdk

Documentation

Index

Constants

View Source
const (
	// ARPProtocolNumber is the ARP network protocol number.
	// TODO: make a protocol interface.
	ARPProtocolNumber = 0x0806

	// ARPSize is the size of an IPv4-over-Ethernet ARP packet.
	ARPSize = 2 + 2 + 1 + 1 + 2 + 2*6 + 2*4

	// Typical ARP opcodes defined in RFC 826.
	ARPRequest uint16 = 1
	ARPReply   uint16 = 2
)
View Source
const (
	ICMPv4EchoReply      uint8 = 0
	ICMPv4DstUnreachable uint8 = 3
	ICMPv4SrcQuench      uint8 = 4
	ICMPv4Redirect       uint8 = 5
	ICMPv4Echo           uint8 = 8
	ICMPv4TimeExceeded   uint8 = 11
	ICMPv4ParamProblem   uint8 = 12
	ICMPv4Timestamp      uint8 = 13
	ICMPv4TimestampReply uint8 = 14
	ICMPv4InfoRequest    uint8 = 15
	ICMPv4InfoReply      uint8 = 16
)

Typical values of ICMPv4Type defined in RFC 792.

View Source
const (
	IPv4ProtocolNumber = 0x0800
	IPv6ProtocolNumber = 0x86DD
)
View Source
const (
	MaxFrameSize      = 1526 // max frame size
	EthMACAddressSize = 6
	EthEtherTypeSize  = 2
	EthHeaderSize     = EthEtherTypeSize + 2*EthMACAddressSize
)
View Source
const (
	PATH_SYSFS_PCI_DEVICES = "/sys/bus/pci/devices"

	PCI_MAX_RESOURCE = 6 // At most there 6 BARs from 0 to 5, but most devices just use 2 or 3 BARs.
	// IO resource type
	IORESOURCE_IO  = 0x00000100
	IORESOURCE_MEM = 0x00000200
)
View Source
const (
	IFF_TUN   = 0x0001
	IFF_TAP   = 0x0002
	IFF_NO_PI = 0x1000
)
View Source
const (
	UDPHeaderLength uint8 = 8 // udp header length

	IPHeaderLength uint8 = 20 // normallly ip header length is 20
)

Variables

View Source
var ICMPv4ProtocolNumber uint8 = 1

Functions

func ARPHandle

func ARPHandle(l2l *L2Layer, skb *SkBuff)

func ICMPRcv

func ICMPRcv(_ *L3Layer, packet IPv4)

TODO: handle ICMP message

func ICMPSend

func ICMPSend(packet ICMPv4)

func IpSelectIdent

func IpSelectIdent(ip IPv4) uint32

func JHash3Words

func JHash3Words(a, b, c, initval uint32) uint32

JHash3Words is a Jenkins hash support, adapted from Linux kernel include/linux/jhash.h, origin is http://burtleburtle.net/bob/hash/. These are the credits from Bob's sources: lookup3.c, by Bob Jenkins, May 2006, Public Domain.

func Register

func Register(device Device)

Register registers a device to global device list

func RegisterBus

func RegisterBus(bus Bus)

func SendUDP

func SendUDP(skb *SkBuff)

Types

type ARP

type ARP []byte

ARP represents the arp packet.

func (ARP) HardwareAddressSize

func (a ARP) HardwareAddressSize() int

HardwareAddressSize specifies the size of l2 hardware address.

func (ARP) HardwareType

func (a ARP) HardwareType() uint16

HardwareType is the l2 hardware type, often ethernet (1).

func (ARP) InitIPv4OverEthernetARPPacket

func (a ARP) InitIPv4OverEthernetARPPacket(op uint16)

func (ARP) Op

func (a ARP) Op() uint16

Op is the ARP opcode.

func (ARP) ProtocolAddressSize

func (a ARP) ProtocolAddressSize() int

ProtocolAddressSize specifies the size of l3 network address.

func (ARP) ProtocolType

func (a ARP) ProtocolType() uint16

ProtocolType is the type for l3 network type, often IPv4 (0x0800).

func (ARP) SenderHardwareAddress

func (a ARP) SenderHardwareAddress() []byte

SenderHardwareAddress is the link address of the sender. It is a view on to the ARP packet so it can be used to set the value.

func (ARP) SenderProtocolAddress

func (a ARP) SenderProtocolAddress() []byte

SenderProtocolAddress is the protocol address of the sender. It is a view on to the ARP packet so it can be used to set the value.

func (ARP) TargetHardwareAddress

func (a ARP) TargetHardwareAddress() []byte

TargetHardwareAddress is the link address of the target. It is a view on to the ARP packet so it can be used to set the value.

func (ARP) TargetProtocolAddress

func (a ARP) TargetProtocolAddress() []byte

TargetProtocolAddress is the protocol address of the target. It is a view on to the ARP packet so it can be used to set the value.

type Bus

type Bus interface {
	Name() string
	Probe()
	Scan()
}

func NewPCIBus

func NewPCIBus() Bus

type Device

type Device interface {
	Name() string
}

type Driver

type Driver interface {
	Probe()
	Remote()
}

type Echo

type Echo []byte

An Echo represents an ICMP echo request or reply message body.

func (Echo) Data

func (e Echo) Data() []byte

func (Echo) ID

func (e Echo) ID() []byte

func (Echo) Seq

func (e Echo) Seq() []byte

type Frame

type Frame []byte

Link layer frame

func (Frame) Destination

func (f Frame) Destination() []byte

Destination is the mac destination address.

func (Frame) EtherType

func (f Frame) EtherType() []byte

EtherType is the ethernet type.

func (Frame) Packet

func (f Frame) Packet() []byte

Packet returns frame payload.

func (Frame) Source

func (f Frame) Source() []byte

Source is the mac source address.

type ICMPv4

type ICMPv4 []byte

ICMPv4 represents an ICMPv4 header stored in a byte array.

func (ICMPv4) Checksum

func (b ICMPv4) Checksum() []byte

func (ICMPv4) Code

func (b ICMPv4) Code() uint8

func (ICMPv4) SetCode

func (b ICMPv4) SetCode(code uint8)

func (ICMPv4) SetType

func (b ICMPv4) SetType(typ uint8)

func (ICMPv4) Type

func (b ICMPv4) Type() uint8

type IPv4

type IPv4 []byte

IPv4

func (IPv4) Checksum

func (b IPv4) Checksum() uint16

Checksum returns header checksum.

func (IPv4) DestinationAddress

func (b IPv4) DestinationAddress() []byte

DestinationAddress returns IP destination address.

func (IPv4) Flags

func (b IPv4) Flags() uint8

Flags returns segmentation flags of the header.

func (IPv4) FlagsOffset

func (b IPv4) FlagsOffset() uint16

flagsOffset returns flags and offset filed of the header.

func (IPv4) FragmentOffset

func (b IPv4) FragmentOffset() uint16

FragmentOffset returns offset of the IP fragment.

func (IPv4) HeaderLength

func (b IPv4) HeaderLength() uint8

HeaderLength returns IPv4 headerlength, it's unit is 4.

func (IPv4) Identification

func (b IPv4) Identification() uint16

Identification returns identification of the IPv4 header.

func (IPv4) Message

func (b IPv4) Message() []byte

func (IPv4) Protocol

func (b IPv4) Protocol() uint8

Protocol returns the protocol used in the data portion.

func (IPv4) SetChecksum

func (b IPv4) SetChecksum(cks uint16)

func (IPv4) SetHeaderLength

func (b IPv4) SetHeaderLength(l uint8)

func (IPv4) SetIdentification

func (b IPv4) SetIdentification(id uint16)

SetIdentification sets packet ID for this IPv4 packet.

func (IPv4) SetProtocol

func (b IPv4) SetProtocol(p uint8)

func (IPv4) SetTTL

func (b IPv4) SetTTL(ttl uint8)

func (IPv4) SetToS

func (b IPv4) SetToS(tos uint8)

func (IPv4) SetTotalLength

func (b IPv4) SetTotalLength(totl uint16)

func (IPv4) SetVersion

func (b IPv4) SetVersion(v uint8)

func (IPv4) SourceAddress

func (b IPv4) SourceAddress() []byte

SourceAddress returns IP source address.

func (IPv4) TTL

func (b IPv4) TTL() uint8

TTL returns the time to live.

func (IPv4) ToS

func (b IPv4) ToS() uint8

ToS returns IPv4 type of service.

func (IPv4) TotalLength

func (b IPv4) TotalLength() uint16

TotalLength returns the total length of the IPv4 header and payload.

func (IPv4) Version

func (b IPv4) Version() uint8

Version returns IPv4 version, it's always 4.

type L2Layer

type L2Layer struct {
	*TapDevice
}

func (*L2Layer) Loop

func (l2l *L2Layer) Loop()

func (*L2Layer) Read

func (l2l *L2Layer) Read() (*SkBuff, error)

func (*L2Layer) Send

func (l2l *L2Layer) Send(frame Frame)

type L3Layer

type L3Layer struct {
	*L2Layer
}

L3Layer is a IP layer.

func (*L3Layer) IPRcv

func (l3 *L3Layer) IPRcv(l2l *L2Layer, skb *SkBuff)

IPHandle handles IP packet.

func (*L3Layer) IPSend

func (l3 *L3Layer) IPSend(skb *SkBuff)

type MemResource

type MemResource struct {
	PhysicalAddress uint64
	Length          uint64
	Address         []byte
}

type PCIAddress

type PCIAddress struct {
	Domain   uint16
	Bus      uint8
	Device   uint8
	Function uint8
}

type PCIBus

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

func (PCIBus) Name

func (p PCIBus) Name() string

func (*PCIBus) Probe

func (p *PCIBus) Probe()

func (*PCIBus) Scan

func (p *PCIBus) Scan()

type PCIDevice

type PCIDevice struct {
	PCIAddress
	Vendor          uint16
	Device          uint16
	SubsystemVendor uint16
	SubsystemDevice uint16
	Class           uint32
	MaxVFs          uint16
	NumaNode        uint64

	Driver string
	Mem    []MemResource

	HwAddress []byte
	// contains filtered or unexported fields
}

func (PCIDevice) Name

func (p PCIDevice) Name() string

type SkBuff

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

SkBuff is a buffer used for socket, it can be prepended from the head.

func NewSkBuff

func NewSkBuff(size int) *SkBuff

func (*SkBuff) Data

func (skb *SkBuff) Data() []byte

func (*SkBuff) Prepend

func (skb *SkBuff) Prepend(size uint8)

func (*SkBuff) TrimFront

func (skb *SkBuff) TrimFront(size int)

type TapDevice

type TapDevice struct {
	net.HardwareAddr
	*os.File
}

func NewTAP

func NewTAP(name string) (*TapDevice, error)

NewTAP creates a new tap device with the name

type UDP

type UDP []byte

UDP

Directories

Path Synopsis
asm
examples

Jump to

Keyboard shortcuts

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