Page 1 of 1

test network send/receive with tap device ?

Posted: Tue Dec 20, 2016 7:38 pm
by szhou42
Hi, i m writing a rtl8139 card driver.

I am now able to send a raw packet, and capture the packet with qemu's "-net dump" command

Code: Select all

    char * str = "aaaaaaaaaa";
    ethernet_send_packet(mac_addr, str, strlen(str), 0x0021);
qemu's dump:
0000000: d4c3 b2a1 0200 0400 0000 0000 0000 0000  ................
0000010: 0000 0100 0100 0000 66cb 5958 195c 0500  ........f.YX.\..
0000020: 1800 0000 1800 0000 1234 5678 1234 1234  .........4Vx.4.4
0000030: 5678 1234 2100 6161 6161 6161 6161 6161  Vx.4!.aaaaaaaaaa
However, the packet could not be captured by listening the tap device I created.

These are the steps I used to setup the tap device

1 add this to the /etc/network/interface

Code: Select all

        auto br0
        iface br0 inet dhcp
        bridge_ports eth0
        bridge_stp off
        bridge_maxwait 0
        bridge_fd 0
2 sudo brctl addbr br0

3 sudo qemu-system-i386 -kernel os_kernel -net nic,model=rtl8139,macaddr=12:34:56:78:12:34 -net dump,file=traffic.pcap -netdev tap,id=br0 -device rtl8139,netdev=br0

So, when I send a packet from my os to itself(by mac address), tcpdump -i br0 did not capture anything.
Also, the rtl8139 interrupt did fire when the packet was sent, but it never fire again(it should, because the packet was sent to itself)

Did I do something wrong here?
Is the rtl8139 supposed to recognize the format of my ethernet packet and send it to the destination?

Re: test network send/receive with tap device ?

Posted: Wed Dec 21, 2016 12:59 am
by szhou42
:) Never mind, i figure it out.

Code: Select all

tcpdump -i br0 -A
06:53:16.740129 52:54:00:12:34:56 (oui Unknown) > 52:54:00:12:34:56 (oui Unknown), ethertype Unknown (0x2100), length 24:
	0x0000:  6161 6161 6161 6161 6161                 aaaaaaaaaa
For those having the same problem, see this post
http://f.osdev.org/viewtopic.php?f=1&t=30546&start=0