问题描述
我在运行Linux的两台PC之间生成流量(通过发送以太网帧),目的是捕获一些错误帧.问题是当Phy层在帧上检测到错误时(如果CRC或FCS无效),则该帧被丢弃,我无法在程序中接收到它.
I generate a traffic between two PCs running Linux (by sending Ethernet frames), the goal of this is to capture some errors frames. The problem is when the Phy layer detect an error on a frame (if the CRC or FCS is not valid) the frame is dropped and I can't receive it in my program.
有什么方法可以接收错误的帧(例如,禁用Phy层中的丢包并接收指示该帧错误的指示符),以及如何查询NIC卡的统计信息(丢包数量). ..etc).
Are the any way to receive the wrong frame (disable the drops in the Phy layer and receiving a indicator that indicate that this frame is wrong for example) and how can i consult the statistic of the NIC card (number of drops ...etc).
推荐答案
您没有指定哪个操作系统,但我至少可以说Linux:
You didn't specify which OS, but I can at least speak for Linux:
它可能在您的内核,NIC和驱动程序以及ethtool版本上.
It may on your kernel, NIC and driver as well as ethtool versions.
我们需要告诉驱动程序/硬件执行通常不执行的两项操作:1)将FCS字段传递到网络堆栈. (通常这会在传递之前被截断)2)不要丢弃具有错误FCS字段的数据包,而是按原样向上传递它们
We need to tell the driver/hardware to do two things it doesn't normally do:1) Pass the FCS field up the networking stack. (Generally this gets truncated before being passed up)2) Not drop packets with bad FCS fields, instead pass them up as-is
有两个ethtool选项可以实现这些目标:
There are two ethtool options to achieve each of these:
ethtool -K eth0 rx-fcs on #1 above: give us the FCS field
ethtool -K eth0 rx-all on #2 above: even receive bad packets
有了这些,即使它们不正确,我也可以使用wirehark或tcpdump查看FCS字段. (在我的情况下,我有一些网络设备用准确的时间戳即时替换了校验和-这会导致数据包显示为错误",并且我使用上面的方法进行恢复)
With these, I am able to use wireshark or tcpdump to view FCS fields, even if they are not correct. (in my case I have some network device that replaces the checksum on-the-fly with an accurate timestamp - which causes the packets to appear 'bad', and I use the above to recover)
并非所有卡都可以实现此功能!他们可能关闭了上述ethtool选项,或者对它们没有响应.
Not all cards will implement this! They may have the above ethtool options 'fixed' off or not respond to them.
在1G速度下,我已经看到e1000卡运行良好.在10G级别,我还没有找到可以完全做到这一点的NIC,并且必须依靠更复杂的数据采集卡.
At 1G speeds I've seen e1000 cards work well. At 10G I am yet to find a NIC that does this at all, and have to rely on more complex data acquisition cards.
同样,我不知道最低的内核/ethtool版本要求是什么,但是我确实记得必须升级CentOS服务器才能使其正常工作.
Again, I don't know what the minimum kernel/ethtool version requirements are, but I do recall haveing to upgrade a CentOS server in order to get it to work.
我也知道r8169和e1000驱动程序/卡可以做到,但根本不能说其他任何组合.
I also know that r8169 and e1000 drivers/cards can do it, but can't speak for any other combination at all.
还要注意,您将无法在发送它们的计算机上捕获传出的FCS值,因为它们是在添加过程中添加的很晚的(可能已卸载到卡本身),因此pcap将看不到它们.
Also note you won't be able to capture outgoing FCS values on the machine you're sending them because they're added quite late in the process (perhaps offloaded to the card itself) so will not be visible to pcap.
在具有ethtool 3.10的Linux 3.10.11内核上:
On a Linux 3.10.11 kernel, with ethtool 3.10:
$ ethtool -k eth0
Features for eth0:
rx-checksumming: on
tx-checksumming: on
tx-checksum-ipv4: off [fixed]
tx-checksum-ip-generic: on
tx-checksum-ipv6: off [fixed]
tx-checksum-fcoe-crc: off [fixed]
tx-checksum-sctp: off [fixed]
scatter-gather: on
tx-scatter-gather: on
tx-scatter-gather-fraglist: off [fixed]
tcp-segmentation-offload: on
tx-tcp-segmentation: on
tx-tcp-ecn-segmentation: off [fixed]
tx-tcp6-segmentation: on
udp-fragmentation-offload: off [fixed]
generic-segmentation-offload: on
generic-receive-offload: on
large-receive-offload: off [fixed]
rx-vlan-offload: on
tx-vlan-offload: on
ntuple-filters: off [fixed]
receive-hashing: on
highdma: on [fixed]
rx-vlan-filter: on [fixed]
vlan-challenged: off [fixed]
tx-lockless: off [fixed]
netns-local: off [fixed]
tx-gso-robust: off [fixed]
tx-fcoe-segmentation: off [fixed]
tx-gre-segmentation: off [fixed]
tx-udp_tnl-segmentation: off [fixed]
fcoe-mtu: off [fixed]
tx-nocache-copy: on
loopback: off [fixed]
rx-fcs: off
rx-all: off
tx-vlan-stag-hw-insert: off [fixed]
rx-vlan-stag-hw-parse: off [fixed]
rx-vlan-stag-filter: off [fixed]
然后:
$ sudo ethtool -K eth0 rx-fcs on rx-all on
给我:
$ ethtool -k eth0
Features for eth0:
rx-checksumming: on
tx-checksumming: on
tx-checksum-ipv4: off [fixed]
tx-checksum-ip-generic: on
tx-checksum-ipv6: off [fixed]
tx-checksum-fcoe-crc: off [fixed]
tx-checksum-sctp: off [fixed]
scatter-gather: on
tx-scatter-gather: on
tx-scatter-gather-fraglist: off [fixed]
tcp-segmentation-offload: on
tx-tcp-segmentation: on
tx-tcp-ecn-segmentation: off [fixed]
tx-tcp6-segmentation: on
udp-fragmentation-offload: off [fixed]
generic-segmentation-offload: on
generic-receive-offload: on
large-receive-offload: off [fixed]
rx-vlan-offload: on
tx-vlan-offload: on
ntuple-filters: off [fixed]
receive-hashing: on
highdma: on [fixed]
rx-vlan-filter: on [fixed]
vlan-challenged: off [fixed]
tx-lockless: off [fixed]
netns-local: off [fixed]
tx-gso-robust: off [fixed]
tx-fcoe-segmentation: off [fixed]
tx-gre-segmentation: off [fixed]
tx-udp_tnl-segmentation: off [fixed]
fcoe-mtu: off [fixed]
tx-nocache-copy: on
loopback: off [fixed]
rx-fcs: on
rx-all: on
tx-vlan-stag-hw-insert: off [fixed]
rx-vlan-stag-hw-parse: off [fixed]
rx-vlan-stag-filter: off [fixed]
这篇关于如何接收错误的以太网帧并禁用CRC/FCS计算?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!