#include #include #include #include MODULE_LICENSE("GPL"); struct net_device *dev; static int my_eth_init(struct net_device *dev) { // Initialize device netif_start_queue(dev); printk(KERN_INFO "Postens initades\n"); return 0; } static void my_eth_exit(struct net_device *dev) { // Cleanup device pr_info(KERN_INFO "Posten slutade\n"); netif_stop_queue(dev); } static netdev_tx_t my_eth_start_xmit(struct sk_buff *skb, struct net_device *dev) { // Start xmit printk(KERN_INFO "Posten ska skicka nåt\n"); printk("len: %d\n", skb->len); for (int i = 0; i < skb->len; i++) { printk("data: %c\n", skb->data[i]); } printk("protocol: %d\n", skb->protocol); netif_receive_skb(skb); return NETDEV_TX_OK; } static struct net_device_ops my_netdev_ops = { .ndo_init = my_eth_init, .ndo_uninit = my_eth_exit, .ndo_start_xmit = my_eth_start_xmit }; void init_poster(struct net_device *dev) { dev->netdev_ops = &my_netdev_ops; printk(KERN_INFO "Postens allokerades\n"); } struct net_device testcard; int register_device(void) { printk(KERN_INFO "Posten skapas\n"); dev = alloc_netdev(0, "post%d", NET_NAME_UNKNOWN, init_poster); if (!dev) return -ENOMEM; if (register_netdev(dev)) { printk(KERN_ERR "Men vafan Linux vill inte registrera postjävel :(\n"); free_netdev(dev); return -ENODEV; } return 0; } int __init custom_init(void) { int err; if ((err = register_device())) { printk(KERN_ERR "Postjävel funkar inte\n"); return err; } return 0; } void __exit custom_exit(void) { if (!dev) { printk(KERN_ERR "Postjävel finns inte :/\n"); return; } unregister_netdev(dev); free_netdev(dev); printk(KERN_INFO "Posten försvann :,)\n"); } module_init(custom_init); module_exit(custom_exit);