一 网络设备利用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);
}

 

      

GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:23 天前 )
186a802e added ecosystem file for PM2 4 年前
5def40a3 Add host customization support for the NodeJS version 4 年前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐