mirror of
https://github.com/impact-eintr/netstack.git
synced 2025-10-05 21:06:50 +08:00
向网络层写入数据后 需要使用arp协议(网络层协议)来找到目标主机地址 下一步实现arp
This commit is contained in:
@@ -45,8 +45,8 @@ type NIC struct {
|
||||
|
||||
mu sync.RWMutex
|
||||
spoofing bool
|
||||
promiscuous bool // 混杂模式
|
||||
primary map[tcpip.NetworkProtocolNumber]*ilist.List
|
||||
promiscuous bool // 混杂模式
|
||||
primary map[tcpip.NetworkProtocolNumber]*ilist.List // 网络协议号:网络端实现
|
||||
// 网络层端的记录 IP:网络端实现
|
||||
endpoints map[NetworkEndpointID]*referencedNetworkEndpoint
|
||||
// 子网的记录
|
||||
@@ -189,6 +189,33 @@ func (n *NIC) removeEndpoint(r *referencedNetworkEndpoint) {
|
||||
n.mu.Unlock()
|
||||
}
|
||||
|
||||
// primaryEndpoint returns the primary endpoint of n for the given network
|
||||
// protocol.
|
||||
// 根据网络层协议号找到对应的网络层端
|
||||
func (n *NIC) primaryEndpoint(protocol tcpip.NetworkProtocolNumber) *referencedNetworkEndpoint {
|
||||
n.mu.RLock()
|
||||
defer n.mu.RUnlock()
|
||||
|
||||
list := n.primary[protocol]
|
||||
if list == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
for e := list.Front(); e != nil; e = e.Next() {
|
||||
r := e.(*referencedNetworkEndpoint)
|
||||
// TODO: allow broadcast address when SO_BROADCAST is set.
|
||||
switch r.ep.ID().LocalAddress {
|
||||
case header.IPv4Broadcast, header.IPv4Any:
|
||||
continue
|
||||
}
|
||||
if r.tryIncRef() {
|
||||
return r
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// 根据address参数找到对应的网络层端
|
||||
func (n *NIC) findEndpoint(protocol tcpip.NetworkProtocolNumber, address tcpip.Address,
|
||||
peb PrimaryEndpointBehavior) *referencedNetworkEndpoint {
|
||||
@@ -350,6 +377,10 @@ func (n *NIC) DeliverNetworkPacket(linkEP LinkEndpoint, remoteLinkAddr, localLin
|
||||
n.stack.stats.IP.InvalidAddressesReceived.Increment()
|
||||
}
|
||||
|
||||
func (n *NIC) ID() tcpip.NICID {
|
||||
return n.id
|
||||
}
|
||||
|
||||
// 网络端引用
|
||||
type referencedNetworkEndpoint struct {
|
||||
ilist.Entry
|
||||
|
Reference in New Issue
Block a user