由于sk_buff
字段是在本地处理的,因此将它存储在主机顺序中更有意义。像sk_buff->vlan_tci
这样的字段是主机顺序。是否有理由以网络/大端格式存储某些字段sk_buff->protocol
,sk_buff->vlan_proto
?
答案 0 :(得分:4)
根据http://vger.kernel.org/~davem/skb.html页面,protocol
的{{1}}字段由网络使用:
sk_buff
'协议'字段由例如' eth_type_trans()'等例程初始化。它采用了其中一个ETH_P _ *'在< linux / if_ether.h'中定义的值头文件。即使是非以太网设备也使用这些以太网协议类型值来指示应该接收数据包的协议。只要我们总是为每个协议都有一些以太网协议值,这应该不是问题。
此外,skbuff.h
中的评论表明unsigned short protocol,
来自驱动程序:
protocol
因此,对于传入的数据包340 /**
341 * struct sk_buff - socket buffer
369 * @protocol: Packet protocol from driver
391 * @vlan_proto: vlan encapsulation protocol
392 * @vlan_tci: vlan tag control information
从以太网数据包字段填充" TYPE" (ethertype,network endian)
http://en.wikipedia.org/wiki/Ethernet_frame:
以太网上的数据首先传输最重要的八位字节。然而,在每个八位字节内,首先发送最低有效位。 以太网类型(以太网II)或长度为2个八位字节
对于传出数据包,它由网络堆栈填充,然后用于填充" TYPE"字段。
protocol
是来自以太网数据包的第一个vlan_proto
字段的副本,使用802.1Q tagging时通常为0x8100(http://en.wikipedia.org/wiki/EtherType将其列为" VLAN标记的帧( IEEE 802.1Q)")。第二个协议字段(在VLAN标记之后)将用作实际protocol
。因此,protocol
也存储为网络订单,因为它来自/到网络。
TCI(要存储在vlan_proto
中的信息)也是网络802.1q packet的一部分,它有2个字节(八位字节)。但在处理网络字段时,它会被vlan_untag()
in net/8021q/vlan_core.c转换为主机格式:
vlan_tci
我认为可以更轻松地在TCI上进行位操作。从TCI获取PCP(3位),DEI(1位)和VID(12位)字段需要它们。还有一些标记VLAN_TAG_PRESENT
存储在118 struct sk_buff *vlan_untag(struct sk_buff *skb)
119 {
120 struct vlan_hdr *vhdr;
121 u16 vlan_tci;
135 vhdr = (struct vlan_hdr *) skb->data;
136 vlan_tci = ntohs(vhdr->h_vlan_TCI);
137 __vlan_hwaccel_put_tag(skb, skb->protocol, vlan_tci);
__vlan_hwaccel_put_tag
将主机TCI转换为网络以用于传出数据包vlan_insert_tag()
from linux/if_vlan.h:
vlan_tci