#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define err(msg) printk(KERN_INFO "%s failed.\n", msg)
static struct net_device *netdev;
static struct net_device_stats stats;
static int netdev_open(struct net_device *dev)
{
netif_start_queue(dev);
printk(KERN_INFO "netdev_open back.\n");
return 0;
}
static int netdev_stop(struct net_device *dev)
{
netif_stop_queue(dev);
printk(KERN_INFO "netdev_stop back.\n");
return 0;
}
static struct net_device_stats * netdev_stats(struct net_device *dev)
{
struct net_device_stats *p = netdev_priv(dev);
printk(KERN_INFO "netdev_stats back.\n");
return p;
}
static int netdev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
{
printk(KERN_INFO "netdev_hard_start_xmit back.\n");
if (skb)
dev_kfree_skb_any(skb);
return 0;
}
static int __init main_init(void)
{
netdev = alloc_etherdev(sizeof(stats));
if (netdev == NULL) {
err("alloc_etherdev");
goto out;
}
netdev->open = netdev_open;
netdev->stop = netdev_stop;
netdev->hard_start_xmit = netdev_hard_start_xmit;
netdev->get_stats = netdev_stats;
memset(netdev->dev_addr, '\0', ETH_ALEN);
if (register_netdev(netdev) != 0) {
err("register_netdev");
goto err;
}
printk(KERN_INFO "virtual network device register success.\n");
return 0;
err:
free_netdev(netdev);
out:
return -1;
}
static void __exit main_exit(void)
{
unregister_netdev(netdev);
free_netdev(netdev);
printk(KERN_INFO "virtual network device unregister success.\n");
}
module_init(main_init);
module_exit(main_exit);
MODULE_LICENSE("GPL");
阅读(746) | 评论(0) | 转发(0) |