Page 1 of 1

test send ethernet packet

Posted: Sun Dec 18, 2016 5:28 pm
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.

Re: test send ethernet packet

Posted: Sun Dec 18, 2016 6:12 pm
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"

Re: test send ethernet packet

Posted: Sun Dec 18, 2016 11:44 pm
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

Re: test send ethernet packet

Posted: Mon Dec 19, 2016 12:08 am
by Gigasoft
I think you have an extra space before the ','.

Re: test send ethernet packet

Posted: Mon Dec 19, 2016 12:27 am
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

Re: test send ethernet packet

Posted: Mon Dec 19, 2016 12:59 am
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: