test send ethernet packet

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
szhou42
Member
Member
Posts: 67
Joined: Thu Apr 28, 2016 12:40 pm
Contact:

test send ethernet packet

Post by szhou42 »

Hi
I just finished the ethernet layer for my os.
Is there a way I can test if my os actually sends out an ethernet packet?
Wireshark seems to display only packets at network layer.
Nable
Member
Member
Posts: 453
Joined: Tue Nov 08, 2011 11:35 am

Re: test send ethernet packet

Post by Nable »

Hi.
Here is a simple way for QEmu (Bochs has similar option):
man qemu-system-x86_64 wrote: -net dump[,vlan=n][,file=file][,len=len]
Dump network traffic on VLAN n to file file (qemu-vlan0.pcap by default). At most len bytes (64k by default) per packet are stored. The file format is libpcap, so it
can be analyzed with tools such as tcpdump or Wireshark. Note: For devices created with '-netdev', use '-object filter-dump,...' instead.
You can also choose another path: create TUN/TAP device, connect VM to it and listen on the TAP interface with wireshark or tcpdump.
man qemu-system-x86_64 wrote: -netdev tap,id=id[,fd=h][,ifname=name][,script=file][,downscript=dfile][,helper=helper]
-net tap[,vlan=n][,name=name][,fd=h][,ifname=name][,script=file][,downscript=dfile][,helper=helper]
Connect the host TAP network interface name to VLAN n.

Use the network script file to configure it and the network script dfile to deconfigure it. If name is not provided, the OS automatically provides one. The default
network configure script is /etc/qemu-ifup and the default network deconfigure script is /etc/qemu-ifdown. Use script=no or downscript=no to disable script execution.

If running QEMU as an unprivileged user, use the network helper helper to configure the TAP interface. The default network helper executable is
/path/to/qemu-bridge-helper.

fd=h can be used to specify the handle of an already opened host TAP interface.

Examples:

#launch a QEMU instance with the default network script
qemu-system-i386 linux.img -net nic -net tap

#launch a QEMU instance with two NICs, each one connected
#to a TAP device
qemu-system-i386 linux.img \
-net nic,vlan=0 -net tap,vlan=0,ifname=tap0 \
-net nic,vlan=1 -net tap,vlan=1,ifname=tap1

#launch a QEMU instance with the default network helper to
#connect a TAP device to bridge br0
qemu-system-i386 linux.img \
-net nic -net tap,"helper=/path/to/qemu-bridge-helper"
szhou42
Member
Member
Posts: 67
Joined: Thu Apr 28, 2016 12:40 pm
Contact:

Re: test send ethernet packet

Post by szhou42 »

Nable wrote:Hi.
Here is a simple way for QEmu (Bochs has similar option):
man qemu-system-x86_64 wrote: -net dump[,vlan=n][,file=file][,len=len]
Dump network traffic on VLAN n to file file (qemu-vlan0.pcap by default). At most len bytes (64k by default) per packet are stored. The file format is libpcap, so it
can be analyzed with tools such as tcpdump or Wireshark. Note: For devices created with '-netdev', use '-object filter-dump,...' instead.
You can also choose another path: create TUN/TAP device, connect VM to it and listen on the TAP interface with wireshark or tcpdump.
man qemu-system-x86_64 wrote: -netdev tap,id=id[,fd=h][,ifname=name][,script=file][,downscript=dfile][,helper=helper]
-net tap[,vlan=n][,name=name][,fd=h][,ifname=name][,script=file][,downscript=dfile][,helper=helper]
Connect the host TAP network interface name to VLAN n.

Use the network script file to configure it and the network script dfile to deconfigure it. If name is not provided, the OS automatically provides one. The default
network configure script is /etc/qemu-ifup and the default network deconfigure script is /etc/qemu-ifdown. Use script=no or downscript=no to disable script execution.

If running QEMU as an unprivileged user, use the network helper helper to configure the TAP interface. The default network helper executable is
/path/to/qemu-bridge-helper.

fd=h can be used to specify the handle of an already opened host TAP interface.

Examples:

#launch a QEMU instance with the default network script
qemu-system-i386 linux.img -net nic -net tap

#launch a QEMU instance with two NICs, each one connected
#to a TAP device
qemu-system-i386 linux.img \
-net nic,vlan=0 -net tap,vlan=0,ifname=tap0 \
-net nic,vlan=1 -net tap,vlan=1,ifname=tap1

#launch a QEMU instance with the default network helper to
#connect a TAP device to bridge br0
qemu-system-i386 linux.img \
-net nic -net tap,"helper=/path/to/qemu-bridge-helper"
Hi Nable

Is this correct?

Code: Select all

qemu-system-i386 -kernel os_kernel -vga std -k en-us -m 2047M -hda ext2_hda.img -hdb ext2_hdb.img -hdc ext2_hdc.img -hdd ext2_hdd.img -net dump [,vlan=0][,file=/tmp/netlog/traffic.log][,len=65535]
Qemu prints this error, i m not sure what it means

Code: Select all

vagrant@vagrant-ubuntu-trusty-32:~/test/osdev$ ./qemu_run.sh
qemu-system-i386: -net dump: drive with bus=0, unit=0 (index=0) exists
Gigasoft
Member
Member
Posts: 856
Joined: Sat Nov 21, 2009 5:11 pm

Re: test send ethernet packet

Post by Gigasoft »

I think you have an extra space before the ','.
Nable
Member
Member
Posts: 453
Joined: Tue Nov 08, 2011 11:35 am

Re: test send ethernet packet

Post by Nable »

Oh, man. You shoudn't put square brackets into command line - this is just a usual way to show that parameter is optional.
Try something like this:

Code: Select all

qemu-system-i386 -kernel os_kernel -vga std -k en-us -m 2047 -hda ext2_hda.img -hdb ext2_hdb.img -hdc ext2_hdc.img -hdd ext2_hdd.img -net dump,file=/tmp/netlog/traffic.log
szhou42
Member
Member
Posts: 67
Joined: Thu Apr 28, 2016 12:40 pm
Contact:

Re: test send ethernet packet

Post by szhou42 »

Nable wrote:Oh, man. You shoudn't put square brackets into command line - this is just a usual way to show that parameter is optional.
Try something like this:

Code: Select all

qemu-system-i386 -kernel os_kernel -vga std -k en-us -m 2047 -hda ext2_hda.img -hdb ext2_hdb.img -hdc ext2_hdc.img -hdd ext2_hdd.img -net dump,file=/tmp/netlog/traffic.log
:oops: :oops: :oops:
Thanks, i m not not a native speaker so i m not aware of the meaning of square brackets :oops:
Post Reply