Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reliably generate Ethernet frame errors in software?

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.

like image 230
brice Avatar asked Jun 13 '11 11:06

brice


People also ask

How are Ethernet frames transmitted?

To transmit frames from one device to another, Ethernet uses Carrier Sense, Multiple Access with Collision Detection (CSMA/CD). In simple terms, Carrier Sense is the detection of the network and any signals being transmitted so a device knows when it's clear to send.

How many Ethernet frames can be at most simultaneously on the fiber link?

This is however not usually a concern, since most Ethernet networks carry packets with a range of lengths and usually transmit a significant proportion of maximum sized frames (the maximum rate of transmission of maximum sized frames is only 812 frames per second).

What does preamble do in an Ethernet frame?

Ethernet Frames A frame holds one packet of data. The first 8 bytes are the preamble. Some Ethernet systems don't transmit continuously, so the preamble is used to synchronize a receive clock before data is transmitted.

Which field would not be found in an Ethernet frame?

Which field would not be found in an Ethernet Frame? Answer: Destination IP: Source and destination IP addresses would be found in the IP packet, not in the Ethernet frame.


1 Answers

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...

like image 100
Oliver Charlesworth Avatar answered Oct 18 '22 07:10

Oliver Charlesworth