17

Question:

I'm testing a section of cable-fault finding software, and I'd like to reliably and reproducibly generate cable faults on a cat5 cable.

At the moment I'm using a meter length of untwisted cable, and wriggle the cable manually next to a power supply, but I cannot detect any faults in the application (I'm reading the Ethernet fault counters off the Ethernet ASIC.) Whether this is because no faults are generated, or because the software/hardware detection is faulty, I cannot tell.

Is there a way to do this in software?

I'd settle for writing something in a higher level language, like Java or python, and as a last resort would be willing to put it together in C, but I'd really rather not re-write an Ethernet driver purely to fix a possible bug.

[EDIT]: I want to create cable faults - not detect them.

[EDIT]: I've transferred large files through FTP and SCP without problems with the doctored cable, and I see no errors coming up while inspecting the traffic with wireshark

[EDIT]: See also a similar question in python.

Solution:

Well, after spending over a day fighting with C, this is the python solution.

First disable automatic checksumming of the ethernet card:

sudo ethtool -K eth1 tx off

Then, send your dodgy frame from python:

#!/usr/bin/env python

from socket import *

#
# Ethernet Frame:
# [
#   [ Destination address, 6 bytes ]
#   [ Source address, 6 bytes      ]
#   [ Ethertype, 2 bytes           ]
#   [ Payload, 40 to 1500 bytes    ]
#   [ 32 bit CRC chcksum, 4 bytes  ]
# ]
#

s = socket(AF_PACKET, SOCK_RAW)
s.bind(("eth1", 0))
src_addr = "\x01\x02\x03\x04\x05\x06"
dst_addr = "\x01\x02\x03\x04\x05\x06"
payload = ("["*30)+"PAYLOAD"+("]"*30)
checksum = "\x00\x00\x00\x00"
ethertype = "\x08\x01"
s.send(dst_addr+src_addr+ethertype+payload+checksum)

Who said it had to be complicated...

PS: I Love Python.

Community
  • 1
  • 1
brice
  • 24,329
  • 7
  • 79
  • 95
  • Are you trying to detect how your software responds to incorrect packets? Or is your software not recognizing such malformed packets and the reason why they are malformed? – Vineet Reynolds Jun 13 '11 at 11:17
  • 1
    Presumably the "fault detector" is performing checksum-based checks. If you're prepared to generate your own Ethernet frames, then you could inject erroneous checksums? – Oliver Charlesworth Jun 13 '11 at 11:17
  • 1
    @Oli - Yes, you're right. It's just checksum based check. Do you of any software that would allow me to put together my own Ethernet frames? – brice Jun 13 '11 at 11:28
  • Seems like you *should* be able to do that in software, but it depends on whether you can "get in ahead" of the fault-finding software. Speaking as a former electronics technician, it should be dead simple to create shorts and opens in the cable itself. (Use two cables if you need to, one shorted and one open.) Other faults would be a little trickier. – Mike Sherrill 'Cat Recall' Jun 13 '11 at 11:28
  • 1
    @brice: If you're working in C, you can send a raw Ethernet frame using `socket(AF_INET, SOCK_RAW, ...)`, and passing it a pointer to a raw buffer that you've generated yourself (e.g. by following the frame layout at http://en.wikipedia.org/wiki/Ethernet_frame). – Oliver Charlesworth Jun 13 '11 at 11:33
  • @Oli. Thanks for your help. I think I'll end up doing that. If you want to write up your comments as an answer, then I'd happily mark it as the solution! – brice Jun 13 '11 at 11:41
  • You could buy a really crappy router, maybe? ;) – Stein G. Strindhaug Jun 16 '11 at 10:28
  • @brice What NIC did you use which supported disabling FSC offloading? – Martin Nov 19 '13 at 21:57
  • @Martin It was at work and I no longer have access to that machine. I'm currently using NVIDIA MCP55 Ethernet built in on an old M2N32 Sli Deluxe motherboard, and it works OK IIRC. Sorry I can't be more help :( – brice Nov 20 '13 at 22:46
  • @brice I tried with Intel 82540EP GigE(e1000 v. 7.3.21-k8-NAPI) and Intel 82579V GigE(e1000e v. 2.1.4-k) NICs, offloaded all the Tx and Rx parameters possible(http://perl.nopaste.dk/p66815), but still when I sent a frame using a script in your initial post, the other host received it as a valid one. This means that host sending the frame still calculated correct FSC. In addition, once I have offloaded all the computing from the NIC, I would expect to see the FSC value in my packet-analyzer(tcpdump, tshark, Wireshark) on host sending the frame, but for some reason I still do not see it there.. – Martin Nov 21 '13 at 11:09
  • I would also run wireshark against the network data using a hub between your two endpoints just to make sure there's nothing funny going on. Additionally, I would check the wireshark Ethernet option, as you may be ignoring FCS entirely. (Not all cards will check the FCS, and not all cards will pass it on to the layer above. These two groups may overlap.) – brice Nov 21 '13 at 17:46
  • You cannot change the checksum, the backend is handling it. – Alexis Paques Aug 09 '18 at 11:16

1 Answers1

7

If you're working in C, you can send a raw Ethernet frame using socket(AF_PACKET, SOCK_RAW, ...), and passing it a pointer to a raw buffer that you've generated yourself (e.g. by following the frame layout at wikipedia ).

It's been a long time since I've done this, so I'm not going to attempt to write a representative code snippet...

brice
  • 24,329
  • 7
  • 79
  • 95
Oliver Charlesworth
  • 267,707
  • 33
  • 569
  • 680