Linux – How to generate socket errors on a bridge

How to generate socket errors on a bridge… here is a solution to the problem.

How to generate socket errors on a bridge

I’m trying to create a test environment to test the handling of network errors between the client and server. I can’t change the software on either one. The two devices will be connected via a Linux bridge, and I’ll use various bandwidth tuning tools to limit bandwidth or block traffic altogether to simulate various error conditions.

Another thing I don’t know how to implement yet is generating socket errors on existing connections. I prefer to use existing Linux tools/utilities, but I can also write my own if there is enough guidance. I’m very familiar with basic networking, TCP and UDP, etc., but not bridging.

Can anyone suggest ways I can generate socket errors, such as by triggering unexpected FIN packets, to both ends of the socket connected across the bridge?

Thanks in advance.


You can easily sniff and make the appropriate RST or FIN packets in a bridge (usually br0) using scapy FIN or RST packets.

The following is an example where RST is sent in the same direction as the packet containing the data.

from scapy.all import *
import random

def sendRST(p):
    flags = p.sprintf("%TCP.flags%")
    if flags != "S":
        ip = p[IP]      # Received IP Packet
        tcp = p[TCP]    # Received TCP Segment
        if ip.len   <= 40:
        i = IP()        # Outgoing IP Packet
        i.dst = ip.dst
        i.src = ip.src
        t = TCP()       # Outgoing TCP Segment
        t.flags = "R"
        t.dport = tcp.dport =
        t.seq = tcp.seq
        new_ack = tcp.seq + 1
        print "RST sent to ",i.dst,":",t.dport

while (1):
PKT = sniff (iface = "br0", filter = "tcp and src host x.x.x.x", count=1, prn=sendRST)

Check the option of sniffing, it’s very powerful 🙂

Hope that helps.

Related Problems and Solutions