engine

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	BROADCAST_MAC_ADDR = []byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
)

Functions

func ParseIpAddr

func ParseIpAddr(ipAddrStr string) ([]byte, error)

func ParseMacAddr

func ParseMacAddr(macAddrStr string) ([]byte, error)

Types

type Config

type Config struct {
	DebugLog     bool                  // 调试日志
	NetIfList    []*NetIfConfig        // 网卡列表
	RoutingTable []*RoutingEntryConfig // 路由表
}

type Engine

type Engine struct {
	DebugLog       bool
	Stop           bool
	NetIfMap       map[string]*NetIf
	RoutingTable   []*RoutingEntry
	Ipv4PktFwdHook func(ipv4Pkt []byte) []byte
}

func InitEngine

func InitEngine(config *Config) (*Engine, error)

func (*Engine) GetNetIf

func (e *Engine) GetNetIf(name string) *NetIf

func (*Engine) RunEngine

func (e *Engine) RunEngine()

func (*Engine) StopEngine

func (e *Engine) StopEngine()

type InNatEntry added in v1.0.1

type InNatEntry struct {
	IpAddr        uint32
	Port          uint16
	LastAliveTime uint32
}

type NetIf

type NetIf struct {
	Name        string
	MacAddr     []byte
	IpAddr      []byte
	NetworkMask []byte
	EthRxChan   chan []byte
	EthTxChan   chan []byte
	LoChan      chan []byte
	Engine      *Engine
	// arp缓存表 key:ip value:mac
	ArpCacheTable     map[uint32]uint64
	ArpCacheTableLock sync.RWMutex
	HandleUdp         func(udpPayload []byte, udpSrcPort uint16, udpDstPort uint16, ipv4SrcAddr []byte)
	NatEnable         bool
	NatTable          map[OutNatEntry]*InNatEntry
	NatTableLock      sync.RWMutex
}

func (*NetIf) GetArpCache

func (i *NetIf) GetArpCache(ipAddr []byte) (macAddr []byte)

func (*NetIf) HandleArp

func (i *NetIf) HandleArp(ethPayload []byte, ethSrcMac []byte)

func (*NetIf) MacAddrToU added in v1.0.1

func (i *NetIf) MacAddrToU(macAddr []byte) (macAddrU uint64)

func (*NetIf) PacketHandle

func (i *NetIf) PacketHandle()

func (*NetIf) RxEthernet added in v1.0.1

func (i *NetIf) RxEthernet(ethFrm []byte)

func (*NetIf) RxIcmp

func (i *NetIf) RxIcmp(ipv4Payload []byte, ipv4SrcAddr []byte)

func (*NetIf) RxIpv4

func (i *NetIf) RxIpv4(ethPayload []byte)

func (*NetIf) RxTcp

func (i *NetIf) RxTcp()

func (*NetIf) RxUdp

func (i *NetIf) RxUdp(ipv4Payload []byte, ipv4SrcAddr []byte)

func (*NetIf) SetArpCache

func (i *NetIf) SetArpCache(ipAddr []byte, macAddr []byte)

func (*NetIf) TxEthernet added in v1.0.1

func (i *NetIf) TxEthernet(ethPayload []byte, ethDstMac []byte, ethProto uint16) []byte

func (*NetIf) TxIcmp

func (i *NetIf) TxIcmp(icmpPayload []byte, seq uint16, ipv4DstAddr []byte) []byte

func (*NetIf) TxIpv4

func (i *NetIf) TxIpv4(ipv4Payload []byte, ipv4HeadProto uint8, ipv4DstAddr []byte) []byte

func (*NetIf) TxTcpAck

func (i *NetIf) TxTcpAck(tcpSrcPort uint16, tcpDstPort uint16, ipv4DstAddr []byte) []byte

func (*NetIf) TxTcpSyn

func (i *NetIf) TxTcpSyn(tcpSrcPort uint16, tcpDstPort uint16, ipv4DstAddr []byte) []byte

func (*NetIf) TxTcpSynAck

func (i *NetIf) TxTcpSynAck(tcpSrcPort uint16, tcpDstPort uint16, ipv4DstAddr []byte) []byte

func (*NetIf) TxUdp

func (i *NetIf) TxUdp(udpPayload []byte, udpSrcPort uint16, udpDstPort uint16, ipv4DstAddr []byte) []byte

func (*NetIf) UToMacAddr added in v1.0.1

func (i *NetIf) UToMacAddr(macAddrU uint64) (macAddr []byte)

type NetIfConfig

type NetIfConfig struct {
	Name        string      // 网卡名
	MacAddr     string      // mac地址
	IpAddr      string      // ip地址
	NetworkMask string      // 子网掩码
	NatEnable   bool        // 网络地址转换
	EthRxChan   chan []byte // 物理层接收管道
	EthTxChan   chan []byte // 物理层发送管道
}

type OutNatEntry added in v1.0.1

type OutNatEntry struct {
	DstIpAddr uint32
	DstPort   uint16
	SrcIpAddr uint32
	SrcPort   uint16
}

type RoutingEntry added in v1.0.1

type RoutingEntry struct {
	DstIpAddr   []byte
	NetworkMask []byte
	NextHop     []byte
	NetIf       string
}

type RoutingEntryConfig added in v1.0.1

type RoutingEntryConfig struct {
	DstIpAddr   string // 目的ip地址
	NetworkMask string // 网络掩码
	NextHop     string // 下一跳
	NetIf       string // 出接口
}

Jump to

Keyboard shortcuts

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