fdbased endpoint

This commit is contained in:
impact-eintr
2022-11-23 11:31:21 +08:00
parent 6011e0f8f3
commit 990a0c2901
7 changed files with 314 additions and 8 deletions

View File

@@ -3,6 +3,15 @@ package stack
import (
"netstack/tcpip"
"netstack/tcpip/buffer"
"sync"
)
const (
CapabilityChecksumOffload LinkEndpointCapabilities = 1 << iota
CapabilityResolutionRequired
CapabilitySaveRestore
CapabilityDisconnectOK
CapabilityLoopback
)
// 所谓 io 就是数据的输入输出,对于网卡来说就是接收或发送数据,
@@ -14,6 +23,9 @@ type LinkEndpoint interface {
// 当这种物理网络不存在时限制通常为64k其中包括IP数据包的最大大小。
MTU() uint32
// Capabilities返回链路层端点支持的功能集。
Capabilities() LinkEndpointCapabilities
// MaxHeaderLength 返回数据链接(和较低级别的图层组合)标头可以具有的最大大小。
// 较高级别使用此信息来保留它们正在构建的数据包前面预留空间。
MaxHeaderLength() uint16
@@ -40,3 +52,33 @@ type NetworkDispatcher interface {
}
type LinkEndpointCapabilities uint
var (
// 传输层协议的注册存储结构 TODO
// 网络层协议的注册存储结构 TODO
linkEPMu sync.RWMutex
nextLinkEndpointID tcpip.LinkEndpointID = 1
linkEndpoints = make(map[tcpip.LinkEndpointID]LinkEndpoint) // 设备注册表 设备号:设备实现
)
// 注册一个链路层设备
func RegisterLinkEndpoint(linkEP LinkEndpoint) tcpip.LinkEndpointID {
linkEPMu.Lock()
defer linkEPMu.Unlock()
v := nextLinkEndpointID
nextLinkEndpointID++
linkEndpoints[v] = linkEP
return v
}
func FindLinkEndpoint(id tcpip.LinkEndpointID) LinkEndpoint {
linkEPMu.RLock()
defer linkEPMu.RUnlock()
return linkEndpoints[id]
}