Linux回环网卡驱动设计(3)


/*
 * The loopback device is special. There is only one instance
 * per network namespace.
 */
static void loopback_setup(struct net_device *dev)
{
 dev->mtu = (16 * 1024) + 20 + 20 + 12;
 dev->flags = IFF_LOOPBACK;
 dev->header_ops = &eth_header_ops;
 dev->netdev_ops = &loopback_ops;
}

/* Setup and register the loopback device. */
static int loopback_net_init(struct net *net)
{
 struct net_device *dev;
 //1.
 dev = alloc_netdev(0, "lo", loopback_setup);

//4.
 register_netdev(dev);

net->loopback_dev = dev;

return 0;
}

/* Registered in net/core/dev.c */
struct pernet_operations __net_initdata loopback_net_ops = {
 .init = loopback_net_init,
 .exit = loopback_net_exit,
};

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/5d25e3fcd9a3bbd6302557d90330c674.html