appneta / tcpreplay

Pcap editing and replay tools for *NIX and Windows - Users please download source from
http://tcpreplay.appneta.com/wiki/installation.html#downloads
1.16k stars 268 forks source link

[Bug] replaying on a loopback interface is broken #732

Closed glebius closed 1 year ago

glebius commented 2 years ago

Starting with 16442ac3b2791df0e0a08034240834daad7c7a12 tcpreplay can no longer replay packets on a loopback interface.

Previous behavior:

>/usr/src/tcpreplay/src/tcpreplay -i lo0 /tmp/1syn.pcap 
Warning: Unable to process unsupported DLT type: BSD loopback (0x0)
Actual: 1 packets (64 bytes) sent in 0.000011 seconds
Rated: 5818181.8 Bps, 46.54 Mbps, 90909.09 pps
Statistics for network device: lo0
        Successful packets:        1
        Failed packets:            0
        Truncated packets:         0
        Retried packets (ENOBUFS): 0
        Retried packets (EAGAIN):  0

After 16442ac3b2791df0e0a08034240834daad7c7a12: >/usr/src/tcpreplay/src/tcpreplay -i lo0 /tmp/1syn.pcap

The operating system is FreeBSD 14. The loopback has type DLT_NULL and tcpreplay has always been known to not recognize it. However, since DLT_NULL doesn't need any special handling tcpreplay just worked on lo0, albeit printing a warning. With that in mind I quickly hacked get_l2_len_protocol() to just accept DLT_NULL. Unfortunately this wasn't enough. Looks like upper stack of the code is now all designed about Ethernet. That is unfortunate, cause sending on loopback is useful functionality that allows to build unit tests with tcpreplay to be run in a virtual environment.

glebius commented 2 years ago

Update: actually just adding DLT_NULL as alias for DLT_RAW works, if --no-flow-stats is also specified.

glebius commented 2 years ago

Update 2: actually removing assertion from flow_decode() is enough to get it working.

fklassen commented 1 year ago

Thanks for PR #733.

LukasRypl commented 8 months ago

I got a similar message from tcpreplay 4.3.3-2+b1 (Debian 11 - bullseye):

Warning in flows.c:flow_decode() line 258:
Unable to process unsupported DLT type: BSD loopback (0x0)

Displaying encapsulation (capinfos and editcap come from tshark package):

capinfos -E DLT0x0.pcap

File encapsulation:  NULL/Loopback

Workaround:

# change encapsulation type to ethernet
editcap -T ether DLT0x0.pcap good.pcap

(posting here in hope to find it later when stuck on tcpreplay 4.3.x)