net_device & net_device_ops .

1. net_device在内核中代表一个网络设备。

网络设备驱动程序只需要填充net_device的具体成员,并注册net_device 即可实现硬件操作函数与内核的挂接。

net_device 是一个巨型结构体,包含了网络设备的属性描述和接口操作:

  1.   
  2.   
  3. struct net_device  
  4.   
  5.       
  6.     char            name[IFNAMSIZ];    //网络设备的具体名字   
  7.   
  8.     struct pm_qos_request_list pm_qos_req;  
  9.   
  10.       
  11.     struct hlist_node   name_hlist;  
  12.       
  13.     char            *ifalias;  
  14.   
  15.       
  16.     unsigned long       mem_end;     //设备说是用的共享内存的起始和结束地址   
  17.     unsigned long       mem_start;    
  18.     unsigned long       base_addr;   //网络设备I/O基地址   
  19.     unsigned int        irq;         //设备使用的中断号   
  20.   
  21.       
  22.   
  23.     unsigned char       if_port;     //指定多端口设备使用哪个端口,仅针对多端口设备   
  24.     unsigned char       dma;         //分配给该设备的 DMA 通道   
  25.   
  26.     unsigned long       state;  
  27.   
  28.     struct list_head    dev_list;  
  29.     struct list_head    napi_list;  
  30.     struct list_head    unreg_list;  
  31.   
  32.       
  33.     unsigned long       features;  
  34. #define NETIF_F_SG           
  35. #define NETIF_F_IP_CSUM          
  36. #define NETIF_F_NO_CSUM          
  37. #define NETIF_F_HW_CSUM          
  38. #define NETIF_F_IPV6_CSUM   16     
  39. #define NETIF_F_HIGHDMA     32     
  40. #define NETIF_F_FRAGLIST    64     
  41. #define NETIF_F_HW_VLAN_TX  128    
  42. #define NETIF_F_HW_VLAN_RX  256    
  43. #define NETIF_F_HW_VLAN_FILTER  512    
  44. #define NETIF_F_VLAN_CHALLENGED 1024       
  45. #define NETIF_F_GSO     2048       
  46. #define NETIF_F_LLTX        4096       
  47.                       
  48. #define NETIF_F_NETNS_LOCAL 8192       
  49. #define NETIF_F_GRO     16384      
  50. #define NETIF_F_LRO     32768      
  51.   
  52.   
  53. #define NETIF_F_FCOE_CRC    (1 << 24)    
  54. #define NETIF_F_SCTP_CSUM   (1 << 25)    
  55. #define NETIF_F_FCOE_MTU    (1 << 26)    
  56. #define NETIF_F_NTUPLE      (1 << 27)    
  57. #define NETIF_F_RXHASH      (1 << 28)    
  58.   
  59.       
  60. #define NETIF_F_GSO_SHIFT   16   
  61. #define NETIF_F_GSO_MASK    0x00ff0000   
  62. #define NETIF_F_TSO     (SKB_GSO_TCPV4 << NETIF_F_GSO_SHIFT)   
  63. #define NETIF_F_UFO     (SKB_GSO_UDP << NETIF_F_GSO_SHIFT)   
  64. #define NETIF_F_GSO_ROBUST  (SKB_GSO_DODGY << NETIF_F_GSO_SHIFT)   
  65. #define NETIF_F_TSO_ECN     (SKB_GSO_TCP_ECN << NETIF_F_GSO_SHIFT)   
  66. #define NETIF_F_TSO6        (SKB_GSO_TCPV6 << NETIF_F_GSO_SHIFT)   
  67. #define NETIF_F_FSO     (SKB_GSO_FCOE << NETIF_F_GSO_SHIFT)   
  68.   
  69.       
  70. #define NETIF_F_GSO_SOFTWARE    (NETIF_F_TSO NETIF_F_TSO_ECN \   
  71.                  NETIF_F_TSO6 NETIF_F_UFO)  
  72.   
  73.   
  74. #define NETIF_F_GEN_CSUM    (NETIF_F_NO_CSUM NETIF_F_HW_CSUM)   
  75. #define NETIF_F_V4_CSUM     (NETIF_F_GEN_CSUM NETIF_F_IP_CSUM)   
  76. #define NETIF_F_V6_CSUM     (NETIF_F_GEN_CSUM NETIF_F_IPV6_CSUM)   
  77. #define NETIF_F_ALL_CSUM    (NETIF_F_V4_CSUM NETIF_F_V6_CSUM)   
  78.   
  79.       
  80. #define NETIF_F_ONE_FOR_ALL (NETIF_F_GSO_SOFTWARE NETIF_F_GSO_ROBUST \   
  81.                  NETIF_F_SG NETIF_F_HIGHDMA      
  82.                  NETIF_F_FRAGLIST)  
  83.   
  84.       
  85.     int         ifindex;  
  86.     int         iflink;  
  87.   
  88.     struct net_device_stats stats;  
  89.     atomic_long_t       rx_dropped;   
  90.   
  91. #ifdef CONFIG_WIRELESS_EXT   
  92.       
  93.     const struct iw_handler_def   wireless_handlers;  
  94.       
  95.     struct iw_public_data wireless_data;  
  96. #endif   
  97.       
  98.     const struct net_device_ops *netdev_ops;  
  99.     const struct ethtool_ops *ethtool_ops;  
  100.   
  101.       
  102.     const struct header_ops *header_ops;  
  103.   
  104.     unsigned int        flags;      //网络接口标志   
  105.     unsigned short      gflags;  
  106.         unsigned int            priv_flags;   
  107.     unsigned short      padded;   
  108.   
  109.     unsigned char       operstate;   
  110.     unsigned char       link_mode;   
  111.   
  112.     unsigned int        mtu;       //最大传输单元   
  113.     unsigned short      type;      //硬件接口的类型   
  114.     unsigned short      hard_header_len;      //网络设备的硬件头长度   
  115.   
  116.       
  117.     unsigned short      needed_headroom;  
  118.     unsigned short      needed_tailroom;  
  119.   
  120.       
  121.     unsigned char       perm_addr[MAX_ADDR_LEN];   
  122.     unsigned char       addr_assign_type;   
  123.     unsigned char       addr_len;     
  124.     unsigned short          dev_id;       
  125.   
  126.     spinlock_t      addr_list_lock;  
  127.     struct netdev_hw_addr_list  uc;   
  128.     struct netdev_hw_addr_list  mc;   
  129.     int         uc_promisc;  
  130.     unsigned int        promiscuity;  
  131.     unsigned int        allmulti;  
  132.   
  133.   
  134.       
  135.   
  136. #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)   
  137.     struct vlan_group __rcu *vlgrp;       
  138. #endif   
  139. #ifdef CONFIG_NET_DSA   
  140.     void            *dsa_ptr;     
  141. #endif   
  142.     void            *atalk_ptr;   
  143.     struct in_device __rcu  *ip_ptr;      
  144.     void                    *dn_ptr;          
  145.     struct inet6_dev __rcu  *ip6_ptr;         
  146.     void            *ec_ptr;      
  147.     void            *ax25_ptr;    
  148.     struct wireless_dev *ieee80211_ptr;   
  149.   
  150.   
  151.     unsigned long       last_rx;      
  152.   
  153.     struct net_device   *master;   
  154.   
  155.       
  156.     unsigned char       *dev_addr;    
  157.   
  158.     struct netdev_hw_addr_list  dev_addrs;   
  159.   
  160.     unsigned char       broadcast[MAX_ADDR_LEN];      
  161.   
  162. #ifdef CONFIG_RPS   
  163.     struct kset     *queues_kset;  
  164.   
  165.     struct netdev_rx_queue  *_rx;  
  166.   
  167.       
  168.     unsigned int        num_rx_queues;  
  169.   
  170.       
  171.     unsigned int        real_num_rx_queues;  
  172. #endif   
  173.   
  174.     rx_handler_func_t   *rx_handler;  
  175.     void            *rx_handler_data;  
  176.   
  177.     struct netdev_queue __rcu *ingress_queue;  
  178.   
  179.   
  180.     struct netdev_queue *_tx ____cacheline_aligned_in_smp;  
  181.   
  182.       
  183.     unsigned int        num_tx_queues;  
  184.   
  185.       
  186.     unsigned int        real_num_tx_queues;  
  187.   
  188.       
  189.     struct Qdisc        *qdisc;  
  190.   
  191.     unsigned long       tx_queue_len;     
  192.     spinlock_t      tx_global_lock;  
  193.   
  194.       
  195.   
  196.       
  197.     unsigned long       trans_start;      
  198.   
  199.     int         watchdog_timeo;   
  200.     struct timer_list   watchdog_timer;  
  201.   
  202.       
  203.     int __percpu        *pcpu_refcnt;  
  204.   
  205.       
  206.     struct list_head    todo_list;  
  207.       
  208.     struct hlist_node   index_hlist;  
  209.   
  210.     struct list_head    link_watch_list;  
  211.   
  212.       
  213.     enum NETREG_UNINITIALIZED=0,  
  214.            NETREG_REGISTERED,     
  215.            NETREG_UNREGISTERING,      
  216.            NETREG_UNREGISTERED,   
  217.            NETREG_RELEASED,       
  218.            NETREG_DUMMY,          
  219.     reg_state:16;  
  220.   
  221.     enum  
  222.         RTNL_LINK_INITIALIZED,  
  223.         RTNL_LINK_INITIALIZING,  
  224.     rtnl_link_state:16;  
  225.   
  226.       
  227.     void (*destructor)(struct net_device *dev);  
  228.   
  229. #ifdef CONFIG_NETPOLL   
  230.     struct netpoll_info *npinfo;  
  231. #endif   
  232.   
  233. #ifdef CONFIG_NET_NS   
  234.       
  235.     struct net      *nd_net;  
  236. #endif   
  237.   
  238.       
  239.     union  
  240.         void                *ml_priv;  
  241.         struct pcpu_lstats __percpu *lstats;   
  242.         struct pcpu_tstats __percpu *tstats;   
  243.         struct pcpu_dstats __percpu *dstats;   
  244.     };  
  245.       
  246.     struct garp_port __rcu  *garp_port;  
  247.   
  248.       
  249.     struct device       dev;  
  250.       
  251.     const struct attribute_group *sysfs_groups[4];  
  252.   
  253.       
  254.     const struct rtnl_link_ops *rtnl_link_ops;  
  255.   
  256.       
  257.     unsigned long vlan_features;  
  258.   
  259.       
  260. #define GSO_MAX_SIZE        65536   
  261.     unsigned int        gso_max_size;  
  262.   
  263. #ifdef CONFIG_DCB   
  264.       
  265.     const struct dcbnl_rtnl_ops *dcbnl_ops;  
  266. #endif   
  267.   
  268. #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)   
  269.       
  270.     unsigned int        fcoe_ddp_xid;  
  271. #endif   
  272.       
  273.     struct ethtool_rx_ntuple_list ethtool_ntuple_list;  
  274.   
  275.       
  276.     struct phy_device *phydev;  
  277. };  
struct net_device {

        
        char                    name[IFNAMSIZ];    //网络设备的具体名字

        struct pm_qos_request_list pm_qos_req;

        
        struct hlist_node       name_hlist;
        
        char                    *ifalias;

        
        unsigned long           mem_end;         //设备说是用的共享内存的起始和结束地址
        unsigned long           mem_start;      
        unsigned long           base_addr;       //网络设备I/O基地址
        unsigned int            irq;             //设备使用的中断号

        

        unsigned char           if_port;         //指定多端口设备使用哪个端口,仅针对多端口设备
        unsigned char           dma;             //分配给该设备的 DMA 通道

        unsigned long           state;

        struct list_head        dev_list;
        struct list_head        napi_list;
        struct list_head        unreg_list;

        
        unsigned long           features;
#define NETIF_F_SG              1       
#define NETIF_F_IP_CSUM         2       
#define NETIF_F_NO_CSUM         4       
#define NETIF_F_HW_CSUM         8       
#define NETIF_F_IPV6_CSUM       16      
#define NETIF_F_HIGHDMA         32      
#define NETIF_F_FRAGLIST        64      
#define NETIF_F_HW_VLAN_TX      128     
#define NETIF_F_HW_VLAN_RX      256     
#define NETIF_F_HW_VLAN_FILTER  512     
#define NETIF_F_VLAN_CHALLENGED 1024    
#define NETIF_F_GSO             2048    
#define NETIF_F_LLTX            4096    
                                        
#define NETIF_F_NETNS_LOCAL     8192    
#define NETIF_F_GRO             16384   
#define NETIF_F_LRO             32768   


#define NETIF_F_FCOE_CRC        (1 << 24) 
#define NETIF_F_SCTP_CSUM       (1 << 25) 
#define NETIF_F_FCOE_MTU        (1 << 26) 
#define NETIF_F_NTUPLE          (1 << 27) 
#define NETIF_F_RXHASH          (1 << 28) 

        
#define NETIF_F_GSO_SHIFT       16
#define NETIF_F_GSO_MASK        0x00ff0000
#define NETIF_F_TSO             (SKB_GSO_TCPV4 << NETIF_F_GSO_SHIFT)
#define NETIF_F_UFO             (SKB_GSO_UDP << NETIF_F_GSO_SHIFT)
#define NETIF_F_GSO_ROBUST      (SKB_GSO_DODGY << NETIF_F_GSO_SHIFT)
#define NETIF_F_TSO_ECN         (SKB_GSO_TCP_ECN << NETIF_F_GSO_SHIFT)
#define NETIF_F_TSO6            (SKB_GSO_TCPV6 << NETIF_F_GSO_SHIFT)
#define NETIF_F_FSO             (SKB_GSO_FCOE << NETIF_F_GSO_SHIFT)

        
#define NETIF_F_GSO_SOFTWARE    (NETIF_F_TSO | NETIF_F_TSO_ECN | \
                                 NETIF_F_TSO6 | NETIF_F_UFO)


#define NETIF_F_GEN_CSUM        (NETIF_F_NO_CSUM | NETIF_F_HW_CSUM)
#define NETIF_F_V4_CSUM         (NETIF_F_GEN_CSUM | NETIF_F_IP_CSUM)
#define NETIF_F_V6_CSUM         (NETIF_F_GEN_CSUM | NETIF_F_IPV6_CSUM)
#define NETIF_F_ALL_CSUM        (NETIF_F_V4_CSUM | NETIF_F_V6_CSUM)

        
#define NETIF_F_ONE_FOR_ALL     (NETIF_F_GSO_SOFTWARE | NETIF_F_GSO_ROBUST | \
                                 NETIF_F_SG | NETIF_F_HIGHDMA |         \
                                 NETIF_F_FRAGLIST)

        
        int                     ifindex;
        int                     iflink;

        struct net_device_stats stats;
        atomic_long_t           rx_dropped; 

#ifdef CONFIG_WIRELESS_EXT
        
        const struct iw_handler_def *   wireless_handlers;
        
        struct iw_public_data * wireless_data;
#endif
        
        const struct net_device_ops *netdev_ops;
        const struct ethtool_ops *ethtool_ops;

        
        const struct header_ops *header_ops;

        unsigned int            flags;      //网络接口标志
        unsigned short          gflags;
        unsigned int            priv_flags; 
        unsigned short          padded; 

        unsigned char           operstate; 
        unsigned char           link_mode; 

        unsigned int            mtu;       //最大传输单元
        unsigned short          type;      //硬件接口的类型
        unsigned short          hard_header_len;          //网络设备的硬件头长度

        
        unsigned short          needed_headroom;
        unsigned short          needed_tailroom;

        
        unsigned char           perm_addr[MAX_ADDR_LEN]; 
        unsigned char           addr_assign_type; 
        unsigned char           addr_len;       
        unsigned short          dev_id;         

        spinlock_t              addr_list_lock;
        struct netdev_hw_addr_list      uc;     
        struct netdev_hw_addr_list      mc;     
        int                     uc_promisc;
        unsigned int            promiscuity;
        unsigned int            allmulti;


        

#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
        struct vlan_group __rcu *vlgrp;         
#endif
#ifdef CONFIG_NET_DSA
        void                    *dsa_ptr;       
#endif
        void                    *atalk_ptr;     
        struct in_device __rcu  *ip_ptr;        
        void                    *dn_ptr;        
        struct inet6_dev __rcu  *ip6_ptr;       
        void                    *ec_ptr;        
        void                    *ax25_ptr;      
        struct wireless_dev     *ieee80211_ptr; 


        unsigned long           last_rx;        

        struct net_device       *master; 

        
        unsigned char           *dev_addr;      

        struct netdev_hw_addr_list      dev_addrs; 

        unsigned char           broadcast[MAX_ADDR_LEN];        

#ifdef CONFIG_RPS
        struct kset             *queues_kset;

        struct netdev_rx_queue  *_rx;

        
        unsigned int            num_rx_queues;

        
        unsigned int            real_num_rx_queues;
#endif

        rx_handler_func_t       *rx_handler;
        void                    *rx_handler_data;

        struct netdev_queue __rcu *ingress_queue;


        struct netdev_queue     *_tx ____cacheline_aligned_in_smp;

        
        unsigned int            num_tx_queues;

        
        unsigned int            real_num_tx_queues;

        
        struct Qdisc            *qdisc;

        unsigned long           tx_queue_len;   
        spinlock_t              tx_global_lock;

        

        
        unsigned long           trans_start;    

        int                     watchdog_timeo; 
        struct timer_list       watchdog_timer;

        
        int __percpu            *pcpu_refcnt;

        
        struct list_head        todo_list;
        
        struct hlist_node       index_hlist;

        struct list_head        link_watch_list;

        
        enum { NETREG_UNINITIALIZED=0,
               NETREG_REGISTERED,       
               NETREG_UNREGISTERING,    
               NETREG_UNREGISTERED,     
               NETREG_RELEASED,         
               NETREG_DUMMY,            
        } reg_state:16;

        enum {
                RTNL_LINK_INITIALIZED,
                RTNL_LINK_INITIALIZING,
        } rtnl_link_state:16;

        
        void (*destructor)(struct net_device *dev);

#ifdef CONFIG_NETPOLL
        struct netpoll_info     *npinfo;
#endif

#ifdef CONFIG_NET_NS
        
        struct net              *nd_net;
#endif

        
        union {
                void                            *ml_priv;
                struct pcpu_lstats __percpu     *lstats; 
                struct pcpu_tstats __percpu     *tstats; 
                struct pcpu_dstats __percpu     *dstats; 
        };
        
        struct garp_port __rcu  *garp_port;

        
        struct device           dev;
        
        const struct attribute_group *sysfs_groups[4];

        
        const struct rtnl_link_ops *rtnl_link_ops;

        
        unsigned long vlan_features;

        
#define GSO_MAX_SIZE            65536
        unsigned int            gso_max_size;

#ifdef CONFIG_DCB
        
        const struct dcbnl_rtnl_ops *dcbnl_ops;
#endif

#if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
        
        unsigned int            fcoe_ddp_xid;
#endif
        
        struct ethtool_rx_ntuple_list ethtool_ntuple_list;

        
        struct phy_device *phydev;
};

--- flags : 指网络接口标志,以IFF_ 开头 (interface flags), 部分标志由内核管理,其他的标志在接口初始化时被设置,以说明接口的能力和特性。

各类接口标志定义如下:

  1.   
  2. #define IFF_UP      0x1        
  3. #define IFF_BROADCAST   0x2       //允许广播   
  4. #define IFF_DEBUG   0x4        
  5. #define IFF_LOOPBACK    0x8       //回环   
  6. #define IFF_POINTOPOINT 0x10          //接口连接点到点链路   
  7. #define IFF_NOTRAILERS  0x20           
  8. #define IFF_RUNNING 0x40           
  9. #define IFF_NOARP   0x80           //不能执行ARP   
  10. #define IFF_PROMISC 0x100          
  11. #define IFF_ALLMULTI    0x200          
  12.   
  13. #define IFF_MASTER  0x400          
  14. #define IFF_SLAVE   0x800          
  15.   
  16. #define IFF_MULTICAST   0x1000         //允许组播   
  17.   
  18. #define IFF_PORTSEL 0x2000             
  19. #define IFF_AUTOMEDIA   0x4000         
  20. #define IFF_DYNAMIC 0x8000         
  21.   
  22. #define IFF_LOWER_UP    0x10000        
  23. #define IFF_DORMANT 0x20000        
  24.   
  25. #define IFF_ECHO    0x40000        
  26.   
  27. #define IFF_VOLATILE    (IFF_LOOPBACK|IFF_POINTOPOINT|IFF_BROADCAST|IFF_ECHO|\   
  28.         IFF_MASTER|IFF_SLAVE|IFF_RUNNING|IFF_LOWER_UP|IFF_DORMANT)  
  29.   
  30.   
  31. #define IFF_802_1Q_VLAN 0x1                
  32. #define IFF_EBRIDGE 0x2        
  33. #define IFF_SLAVE_INACTIVE  0x4    
  34. #define IFF_MASTER_8023AD   0x8    
  35. #define IFF_MASTER_ALB  0x10           
  36. #define IFF_BONDING 0x20           
  37. #define IFF_SLAVE_NEEDARP 0x40         
  38. #define IFF_ISATAP  0x80           
  39. #define IFF_MASTER_ARPMON 0x100        
  40. #define IFF_WAN_HDLC    0x200          
  41. #define IFF_XMIT_DST_RELEASE 0x400    
  42. #define IFF_DONT_BRIDGE 0x800          
  43. #define IFF_IN_NETPOLL  0x1000         
  44. #define IFF_DISABLE_NETPOLL 0x2000     
  45. #define IFF_MACVLAN_PORT    0x4000     
  46. #define IFF_BRIDGE_PORT 0x8000         
  47. #define IFF_OVS_DATAPATH    0x10000   
#define IFF_UP          0x1             
#define IFF_BROADCAST   0x2               //允许广播
#define IFF_DEBUG       0x4             
#define IFF_LOOPBACK    0x8               //回环
#define IFF_POINTOPOINT 0x10              //接口连接点到点链路
#define IFF_NOTRAILERS  0x20            
#define IFF_RUNNING     0x40            
#define IFF_NOARP       0x80               //不能执行ARP
#define IFF_PROMISC     0x100           
#define IFF_ALLMULTI    0x200           

#define IFF_MASTER      0x400           
#define IFF_SLAVE       0x800           

#define IFF_MULTICAST   0x1000             //允许组播

#define IFF_PORTSEL     0x2000          
#define IFF_AUTOMEDIA   0x4000          
#define IFF_DYNAMIC     0x8000          

#define IFF_LOWER_UP    0x10000         
#define IFF_DORMANT     0x20000         

#define IFF_ECHO        0x40000         

#define IFF_VOLATILE    (IFF_LOOPBACK|IFF_POINTOPOINT|IFF_BROADCAST|IFF_ECHO|\
                IFF_MASTER|IFF_SLAVE|IFF_RUNNING|IFF_LOWER_UP|IFF_DORMANT)


#define IFF_802_1Q_VLAN 0x1             
#define IFF_EBRIDGE     0x2             
#define IFF_SLAVE_INACTIVE      0x4     
#define IFF_MASTER_8023AD       0x8     
#define IFF_MASTER_ALB  0x10            
#define IFF_BONDING     0x20            
#define IFF_SLAVE_NEEDARP 0x40          
#define IFF_ISATAP      0x80            
#define IFF_MASTER_ARPMON 0x100         
#define IFF_WAN_HDLC    0x200           
#define IFF_XMIT_DST_RELEASE 0x400      
#define IFF_DONT_BRIDGE 0x800           
#define IFF_IN_NETPOLL  0x1000          
#define IFF_DISABLE_NETPOLL     0x2000  
#define IFF_MACVLAN_PORT        0x4000  
#define IFF_BRIDGE_PORT 0x8000          
#define IFF_OVS_DATAPATH        0x10000 

2. net_device_ops 是操作 net_device的各种操作:

之前linux版本的net_device操作函数,直接就在net_device结构里定义,但是新的linux版本,把这些函数归纳到了 net_device_ops 中了。

  1.   
  2. #define HAVE_NET_DEVICE_OPS   
  3. struct net_device_ops  
  4.     int         (*ndo_init)(struct net_device *dev);  
  5.     void            (*ndo_uninit)(struct net_device *dev);  
  6.     int         (*ndo_open)(struct net_device *dev);  //打开网络接口设备,获得设备需要的I/O地址,IRQ,DMA通道等。   
  7.     int         (*ndo_stop)(struct net_device *dev);  //关闭网络设备   
  8.     netdev_tx_t     (*ndo_start_xmit) (struct sk_buff *skb,   //驱动数据包发送,参数是sk_buff,使得驱动程序获取从上层传递下来的数据包   
  9.                            struct net_device *dev);  
  10.     u16         (*ndo_select_queue)(struct net_device *dev,  
  11.                             struct sk_buff *skb);  
  12.     void            (*ndo_change_rx_flags)(struct net_device *dev,  
  13.                                int flags);  
  14.     void            (*ndo_set_rx_mode)(struct net_device *dev);  
  15.     void            (*ndo_set_multicast_list)(struct net_device *dev);  
  16.     int         (*ndo_set_mac_address)(struct net_device *dev,  
  17.                                void *addr);  
  18.     int         (*ndo_validate_addr)(struct net_device *dev);  
  19.     int         (*ndo_do_ioctl)(struct net_device *dev,  
  20.                             struct ifreq *ifr, int cmd);  
  21.     int         (*ndo_set_config)(struct net_device *dev,  
  22.                               struct ifmap *map);  
  23.     int         (*ndo_change_mtu)(struct net_device *dev,  
  24.                           int new_mtu);  
  25.     int         (*ndo_neigh_setup)(struct net_device *dev,  
  26.                            struct neigh_parms *);  
  27.     void            (*ndo_tx_timeout) (struct net_device *dev);    //当数据包发送超时时,该函数会被调用,该函数需重新启动数据包发送过程,或重新启动硬件等回复网络到正常状态。   
  28.   
  29.     struct rtnl_link_stats64* (*ndo_get_stats64)(struct net_device *dev,  
  30.                              struct rtnl_link_stats64 *storage);  
  31.     struct net_device_stats* (*ndo_get_stats)(struct net_device *dev);  
  32.   
  33.     void            (*ndo_vlan_rx_register)(struct net_device *dev,  
  34.                                 struct vlan_group *grp);  
  35.     void            (*ndo_vlan_rx_add_vid)(struct net_device *dev,  
  36.                                unsigned short vid);  
  37.     void            (*ndo_vlan_rx_kill_vid)(struct net_device *dev,  
  38.                                 unsigned short vid);  
  39. #ifdef CONFIG_NET_POLL_CONTROLLER   
  40.     void                    (*ndo_poll_controller)(struct net_device *dev);  
  41.     int         (*ndo_netpoll_setup)(struct net_device *dev,  
  42.                              struct netpoll_info *info);  
  43.     void            (*ndo_netpoll_cleanup)(struct net_device *dev);  
  44. #endif   
  45.     int         (*ndo_set_vf_mac)(struct net_device *dev,  
  46.                           int queue, u8 *mac);  
  47.     int         (*ndo_set_vf_vlan)(struct net_device *dev,  
  48.                            int queue, u16 vlan, u8 qos);  
  49.     int         (*ndo_set_vf_tx_rate)(struct net_device *dev,  
  50.                               int vf, int rate);  
  51.     int         (*ndo_get_vf_config)(struct net_device *dev,  
  52.                              int vf,  
  53.                              struct ifla_vf_info *ivf);  
  54.     int         (*ndo_set_vf_port)(struct net_device *dev,  
  55.                            int vf,  
  56.                            struct nlattr *port[]);  
  57.     int         (*ndo_get_vf_port)(struct net_device *dev,  
  58.                            int vf, struct sk_buff *skb);  
  59. #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)   
  60.     int         (*ndo_fcoe_enable)(struct net_device *dev);  
  61.     int         (*ndo_fcoe_disable)(struct net_device *dev);  
  62.     int         (*ndo_fcoe_ddp_setup)(struct net_device *dev,  
  63.                               u16 xid,  
  64.                               struct scatterlist *sgl,  
  65.                               unsigned int sgc);  
  66.     int         (*ndo_fcoe_ddp_done)(struct net_device *dev,  
  67.                              u16 xid);  
  68. #define NETDEV_FCOE_WWNN 0   
  69. #define NETDEV_FCOE_WWPN 1   
  70.     int         (*ndo_fcoe_get_wwn)(struct net_device *dev,  
  71.                             u64 *wwn, int type);  
  72. #endif   
  73. };  
#define HAVE_NET_DEVICE_OPS
struct net_device_ops {
        int                     (*ndo_init)(struct net_device *dev);
        void                    (*ndo_uninit)(struct net_device *dev);
        int                     (*ndo_open)(struct net_device *dev);  //打开网络接口设备,获得设备需要的I/O地址,IRQ,DMA通道等。
        int                     (*ndo_stop)(struct net_device *dev);  //关闭网络设备
        netdev_tx_t             (*ndo_start_xmit) (struct sk_buff *skb,   //驱动数据包发送,参数是sk_buff,使得驱动程序获取从上层传递下来的数据包
                                                   struct net_device *dev);
        u16                     (*ndo_select_queue)(struct net_device *dev,
                                                    struct sk_buff *skb);
        void                    (*ndo_change_rx_flags)(struct net_device *dev,
                                                       int flags);
        void                    (*ndo_set_rx_mode)(struct net_device *dev);
        void                    (*ndo_set_multicast_list)(struct net_device *dev);
        int                     (*ndo_set_mac_address)(struct net_device *dev,
                                                       void *addr);
        int                     (*ndo_validate_addr)(struct net_device *dev);
        int                     (*ndo_do_ioctl)(struct net_device *dev,
                                                struct ifreq *ifr, int cmd);
        int                     (*ndo_set_config)(struct net_device *dev,
                                                  struct ifmap *map);
        int                     (*ndo_change_mtu)(struct net_device *dev,
                                                  int new_mtu);
        int                     (*ndo_neigh_setup)(struct net_device *dev,
                                                   struct neigh_parms *);
        void                    (*ndo_tx_timeout) (struct net_device *dev);    //当数据包发送超时时,该函数会被调用,该函数需重新启动数据包发送过程,或重新启动硬件等回复网络到正常状态。

        struct rtnl_link_stats64* (*ndo_get_stats64)(struct net_device *dev,
                                                     struct rtnl_link_stats64 *storage);
        struct net_device_stats* (*ndo_get_stats)(struct net_device *dev);

        void                    (*ndo_vlan_rx_register)(struct net_device *dev,
                                                        struct vlan_group *grp);
        void                    (*ndo_vlan_rx_add_vid)(struct net_device *dev,
                                                       unsigned short vid);
        void                    (*ndo_vlan_rx_kill_vid)(struct net_device *dev,
                                                        unsigned short vid);
#ifdef CONFIG_NET_POLL_CONTROLLER
        void                    (*ndo_poll_controller)(struct net_device *dev);
        int                     (*ndo_netpoll_setup)(struct net_device *dev,
                                                     struct netpoll_info *info);
        void                    (*ndo_netpoll_cleanup)(struct net_device *dev);
#endif
        int                     (*ndo_set_vf_mac)(struct net_device *dev,
                                                  int queue, u8 *mac);
        int                     (*ndo_set_vf_vlan)(struct net_device *dev,
                                                   int queue, u16 vlan, u8 qos);
        int                     (*ndo_set_vf_tx_rate)(struct net_device *dev,
                                                      int vf, int rate);
        int                     (*ndo_get_vf_config)(struct net_device *dev,
                                                     int vf,
                                                     struct ifla_vf_info *ivf);
        int                     (*ndo_set_vf_port)(struct net_device *dev,
                                                   int vf,
                                                   struct nlattr *port[]);
        int                     (*ndo_get_vf_port)(struct net_device *dev,
                                                   int vf, struct sk_buff *skb);
#if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
        int                     (*ndo_fcoe_enable)(struct net_device *dev);
        int                     (*ndo_fcoe_disable)(struct net_device *dev);
        int                     (*ndo_fcoe_ddp_setup)(struct net_device *dev,
                                                      u16 xid,
                                                      struct scatterlist *sgl,
                                                      unsigned int sgc);
        int                     (*ndo_fcoe_ddp_done)(struct net_device *dev,
                                                     u16 xid);
#define NETDEV_FCOE_WWNN 0
#define NETDEV_FCOE_WWPN 1
        int                     (*ndo_fcoe_get_wwn)(struct net_device *dev,
                                                    u64 *wwn, int type);
#endif
};



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值