Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IVMSHM socket and network drivers DRAFT #545

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions W/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Shared memory networking and sockets drivers WIP
5 changes: 5 additions & 0 deletions W/ivshmem-server/cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
sudo ./ivshmem-server -vF -n 10 -M shM -l 16M&
sleep 3
sudo chmod a+rwx /tmp/ivsh*
sudo chmod a+rwx /dev/shm/*
sudo ./ivshmem-client -v
4 changes: 4 additions & 0 deletions W/ivshmem-server/cmd.huge
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sudo ./ivshmem-server -vF -n 10 -m /dev/hugepages -l 16M &
sleep 3
sudo chmod a+rwx /tmp/ivsh*
sudo ./ivshmem-client -v
5 changes: 5 additions & 0 deletions W/ivshmem-server/cmd.no_mem
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
sudo ./ivshmem-server -vF -n 10 &
sleep 3
sudo chmod a+rwx /tmp/ivsh*
sudo chmod a+rwx /dev/shm/*
sudo ./ivshmem-client -v
4 changes: 4 additions & 0 deletions W/ivshmem-server/cmd.orig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sudo ./ivshmem-server -vF -n 10 -m /dev/shm -l 16M&
sleep 3
sudo chmod a+rwx /tmp/ivsh*
sudo ./ivshmem-client -v
4 changes: 4 additions & 0 deletions W/ivshmem-server/cmd_jk
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
./ivshmem-server -vF -n 10 -M shM -l 16M&
sleep 3
chmod a+rwx /tmp/ivsh*
./ivshmem-client -v
8 changes: 8 additions & 0 deletions W/p2p/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
obj-m += p2pnet.o

all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

Empty file added W/p2p/Module.symvers
Empty file.
1 change: 1 addition & 0 deletions W/p2p/modules.order
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/home/vadikas/W/p2p/p2pnet.o
103 changes: 103 additions & 0 deletions W/p2p/p2pnet.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#include <linux/module.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h> // For alloc_etherdev and ethernet operations

#define DRV_NAME "p2pnet"

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Your Name");
MODULE_DESCRIPTION("A simple Linux network driver for P2P networking");
MODULE_VERSION("0.1");

static struct net_device *p2p_net_dev;

// Function prototypes
static int p2p_open(struct net_device *dev);
static int p2p_stop(struct net_device *dev);
static netdev_tx_t p2p_start_xmit(struct sk_buff *skb, struct net_device *dev);
static int p2p_config(struct net_device *dev, struct ifmap *map);
static void p2p_tx_timeout(struct net_device *dev, unsigned int i);

// The net_device_ops structure
static const struct net_device_ops p2p_netdev_ops = {
.ndo_open = p2p_open,
.ndo_stop = p2p_stop,
.ndo_start_xmit = p2p_start_xmit,
.ndo_set_config = p2p_config,
.ndo_tx_timeout = p2p_tx_timeout,
};

// This function is called to open the device
static int p2p_open(struct net_device *dev) {
netif_start_queue(dev);
printk(KERN_INFO "%s: device opened\n", DRV_NAME);
return 0; // success
}

// This function is called to stop the device
static int p2p_stop(struct net_device *dev) {
netif_stop_queue(dev);
printk(KERN_INFO "%s: device stopped\n", DRV_NAME);
return 0; // success
}

// This function is called when a packet needs to be transmitted
static netdev_tx_t p2p_start_xmit(struct sk_buff *skb, struct net_device *dev) {
// Packet transmission code here
// For P2P, you might want to handle packet routing to the correct peer here

dev_kfree_skb(skb); // Free the skb memory
return NETDEV_TX_OK;
}

// This function is called to configure the device
static int p2p_config(struct net_device *dev, struct ifmap *map) {
printk(KERN_INFO "%s: device config \n", DRV_NAME);
if (dev->flags & IFF_UP) {
return -EBUSY;
}
// Config code here
return 0;
}

// This function is called on transmission timeout
static void p2p_tx_timeout(struct net_device *dev,unsigned int i) {
printk(KERN_WARNING "%s: transmit timeout\n", DRV_NAME);
// Timeout handling code here
}

// Module initialization function
static int __init p2p_init_module(void) {
// Allocate the net_device structure
p2p_net_dev = alloc_etherdev(0);
if (!p2p_net_dev) {
return -ENOMEM;
}

// Set the interface name
strncpy(p2p_net_dev->name, "p2p%d", IFNAMSIZ);

// Set the net_device_ops structure
p2p_net_dev->netdev_ops = &p2p_netdev_ops;

// Register the network device
if (register_netdev(p2p_net_dev)) {
printk(KERN_ALERT "%s: error registering net device\n", DRV_NAME);
free_netdev(p2p_net_dev);
return -ENODEV;
}

printk(KERN_INFO "%s: P2P network device registered\n", DRV_NAME);
return 0;
}

// Module cleanup function
static void __exit p2p_cleanup_module(void) {
unregister_netdev(p2p_net_dev);
free_netdev(p2p_net_dev);
printk(KERN_INFO "%s: P2P network device unregistered\n", DRV_NAME);
}

module_init(p2p_init_module);
module_exit(p2p_cleanup_module);

1 change: 1 addition & 0 deletions W/p2p/p2pnet.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/home/vadikas/W/p2p/p2pnet.o
51 changes: 51 additions & 0 deletions W/p2p/p2pnet.mod.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include <linux/module.h>
#define INCLUDE_VERMAGIC
#include <linux/build-salt.h>
#include <linux/elfnote-lto.h>
#include <linux/export-internal.h>
#include <linux/vermagic.h>
#include <linux/compiler.h>

#ifdef CONFIG_UNWINDER_ORC
#include <asm/orc_header.h>
ORC_HEADER;
#endif

BUILD_SALT;
BUILD_LTO_INFO;

MODULE_INFO(vermagic, VERMAGIC_STRING);
MODULE_INFO(name, KBUILD_MODNAME);

__visible struct module __this_module
__section(".gnu.linkonce.this_module") = {
.name = KBUILD_MODNAME,
.init = init_module,
#ifdef CONFIG_MODULE_UNLOAD
.exit = cleanup_module,
#endif
.arch = MODULE_ARCH_INIT,
};

#ifdef CONFIG_RETPOLINE
MODULE_INFO(retpoline, "Y");
#endif



static const struct modversion_info ____versions[]
__used __section("__versions") = {
{ 0x122c3a7e, "_printk" },
{ 0xa2c54569, "consume_skb" },
{ 0x4d0decbc, "alloc_etherdev_mqs" },
{ 0x7e722be1, "register_netdev" },
{ 0xf5617bc3, "free_netdev" },
{ 0xa08af381, "unregister_netdev" },
{ 0xa65c6def, "alt_cb_patch_nops" },
{ 0xb0bb5523, "module_layout" },
};

MODULE_INFO(depends, "");


MODULE_INFO(srcversion, "6520547521D5AAA3151D66E");