linux网络学习之分配net_device结构体

一 网络设备利用net_device结构体来定义,该结构体定义在头函数:kernel/linux/netdevice.h,该结构体的使用函数定义在函数:kernel/net/core/dev.c中:

     该结构体是有函数:alloc_netdev_mps进行分配。

二 alloc_netdev_mps函数解析:

     1 函数原型:struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
  void (*setup)(struct net_device *),
  unsigned int txqs, unsigned int rxqs)

     入参的含义:

 * @sizeof_priv: size of private data to allocate space for
 * @name:  device name format string
 * @setup:  callback to initialize device
 * @txqs:  the number of TX subqueues to allocate
 * @rxqs:  the number of RX subqueues to allocate

    2 使用实例:

       a 环回网络的申请:

        dev = alloc_netdev(0, "lo", loopback_setup); /* alloc zero size loop net  and name is lo*/

        #define alloc_netdev(sizeof_priv, name, setup) \
 alloc_netdev_mqs(sizeof_priv, name, setup, 1, 1)

      b 有线网络的申请:

 /* Allocate and initialise a struct net_device and struct efx_nic */
 net_dev = alloc_etherdev_mqs(sizeof(*efx), EFX_MAX_CORE_TX_QUEUES,
         EFX_MAX_RX_QUEUES);

struct net_device *alloc_etherdev_mqs(int sizeof_priv, unsigned int txqs,
          unsigned int rxqs)
{
 return alloc_netdev_mqs(sizeof_priv, "eth%d", ether_setup, txqs, rxqs);
}

 

      

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值