Implement virtio-net device
Implementation of Virtio-net Device
- Defined struct
virtio_net_devto represent the virtio-net device. - Implemented
virtio_net_initto initialize the TAP device for communication. - Introduced
virtio_net_init_pcito register the virtio-net device on PCI, configure virtqueues. - Implemented functions to handle available events for RX and TX virtqueues.
- Added functions to notify the guest OS about used descriptors after packet processing.
Makefile Modification
- Added rules to compile virtio-net.c into virtio-net.o, ensuring correct compilation and linkage of virtio-net functionality within the project.
Kernel Networking Options Enabled
- Enabled necessary kernel configuration options (
CONFIG_NET,CONFIG_INET,CONFIG_VIRTIO,CONFIG_VIRTIO_NET,CONFIG_NETDEVICES) to support networking functionality. - Enabled specific networking commands required for testing the virtio-net device.
Structural Updates
- Added struct
virtio_net_deventry within structvm_tto facilitate the integration and management of the virtio-net device.
Additional Changes
- Called
virtio_net_initandvirtio_net_init_pciinvm_arch_init_platform_deviceandmainrespectively, ensuring initialization of the virtio-net device before the virtual machine starts.
I have pushed a newer version. Please take a look.
For testing the function, you can use the command below:
Host OS :
sudo ip link delete br0
sudo brctl addbr br0
sudo ip addr add 10.0.0.1/24 dev br0
sudo ip route add default via 10.0.0.1 dev br0
sudo ip link set br0 up
sudo ip link set tap0 master br0
sudo ip link set tap0 up
Guest OS :
ip addr add 10.0.0.2/24 dev eth0
ip link set eth0 up
ip route add default via 10.0.0.1
I'm good with the changes now. Thanks for all the kindly reply.
Let' see if @jserv has any extra comment.
Thanks for your review !
I have pushed the latest version with the following updates:
- I rebased the latest master branch to remove the non-functional commit "Bump linux version to 6.1.91" as discussed in issue #35.
- I have reformatted all relevant files using clang-format. Specifically, I ran the command
find src -name '*.[ch]' | xargs clang-format-12 -iwith clang-format version 12.
- I have reformatted all relevant files using clang-format. Specifically, I ran the command find src -name '*.[ch]' | xargs clang-format-12 -i with clang-format version 12.
Warning: No newline at end of file src/virtio-net.c
See https://medium.com/@alexey.inkin/how-to-force-newline-at-end-of-files-and-why-you-should-do-it-fdf76d1d090e
Thank @jimmylu890303 for contributing!