Stack
RawFactory
图 1: RawFactory 逻辑图
Stack 对象中包含一个 RawFactory 接口实例,用于创建不同类型的 Endpoint**。RawFactory 创建 Endpoint 时,可将当前 Stack 对象作为参数传入,返回的 Endpoint 实现中,包含指向当前 Stack 的指针。这样的设计,可以使 Stack 代码解耦 Endpoint 接口不同实现间的差异,RawFactory 定义如下:
// RawFactory produces endpoints for writing various types of raw packets.type RawFactory interface {// NewUnassociatedEndpoint produces endpoints for writing packets not// associated with a particular transport protocol. Such endpoints can// be used to write arbitrary packets that include the network header.NewUnassociatedEndpoint(stack *Stack, netProto tcpip.NetworkProtocolNumber, transProto tcpip.TransportProtocolNumber, waiterQueue *waiter.Queue) (tcpip.Endpoint, *tcpip.Error)// NewPacketEndpoint produces endpoints for reading and writing packets// that include network and (when cooked is false) link layer headers.NewPacketEndpoint(stack *Stack, cooked bool, netProto tcpip.NetworkProtocolNumber, waiterQueue *waiter.Queue) (tcpip.Endpoint, *tcpip.Error)}
NIC
LinkEndpoint
NIC 代表网络接口卡设备,每个网络接口卡设备都匿名包含一个 LinkEnpoint 接口。LinkEnpoint 用于实现链路层功能。
提问:LinkEndpoint 中为什么需要包含 NetworkLinkEndpoint 接口?
