免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1044 | 回复: 0
打印 上一主题 下一主题

net_device [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-09-21 10:33 |只看该作者 |倒序浏览

               
net_device分析2009-07-09 15:25
先上代码!
复杂版本:
Code:

  Normal
  0
  
  7.8 磅
  0
  2
  
  false
  false
  false
  
   
   
   
   
   
   
   
   
   
   
   
   
  
  MicrosoftInternetExplorer4



/* Style Definitions */
table.MsoNormalTable
        {mso-style-name:普通表格;
        mso-tstyle-rowband-size:0;
        mso-tstyle-colband-size:0;
        mso-style-noshow:yes;
        mso-style-parent:"";
        mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
        mso-para-margin:0cm;
        mso-para-margin-bottom:.0001pt;
        mso-pagination:widow-orphan;
        font-size:10.0pt;
        font-family:"Times New Roman";
        mso-fareast-font-family:"Times New Roman";
        mso-ansi-language:#0400;
        mso-fareast-language:#0400;
        mso-bidi-language:#0400;}
   1. /*
   2.
*  The DEVICE structure.
   3.
*  Actually, this whole structure
is a big mistake.  It mixes I/O
   4.
*  data with strictly "high-level"
data, and it has to know about
   5.
*  almost every data structure
used in the INET module.
   6.  *
   7.
*  FIXME: cleanup struct
net_device such that network protocol info
   8.
*  moves out.
   9.
*/  
  10.   
  11. struct net_device  
  12. {  
  13.   
  14.     /*
  15.     
* This is the first field of the "visible" part of this
structure
  16.     
* (i.e. as seen by users in the "Space.c" file).  It is the name
  17.     
* the interface.
  18.     
*/  
  19.     char            name[IFNAMSIZ];  
  20.     /* device name hash chain */  
  21.     struct hlist_node   name_hlist;  
  22.     /* snmp alias */  
  23.     char            *ifalias;  
  24.   
  25.     /*
  26.     
*  I/O specific fields
  27.     
*  FIXME: Merge these and struct
ifmap into one
  28.     
*/  
  29.     unsigned long       mem_end;    /* shared mem end   */  
  30.     unsigned long       mem_start;  /* shared mem start */  
  31.     unsigned long       base_addr;  /* device I/O address   */  
  32.     unsigned int        irq;        /* device IRQ number    */  
  33.   
  34.     /*
  35.     
*  Some hardware also needs these
fields, but they are not
  36.     
*  part of the usual set specified
in Space.c.
  37.     
*/  
  38.   
  39.     unsigned char       if_port;    /* Selectable AUI, TP,..*/
  40.     unsigned char       dma;        /* DMA channel      */
  41.   
  42.     unsigned long       state;  
  43.   
  44.     struct list_head    dev_list;  
  45.     struct list_head    napi_list;  
  46.   
  47.     /* Net device features */  
  48.     unsigned long       features;  
  49. #define NETIF_F_SG      1   /* Scatter/gather IO. */  
  50. #define NETIF_F_IP_CSUM     2   /* Can checksum TCP/UDP over
IPv4. */  
  51. #define NETIF_F_NO_CSUM     4   /* Does not require checksum.
F.e. loopack. */  
  52. #define NETIF_F_HW_CSUM     8   /* Can checksum all the packets.
*/  
  53. #define NETIF_F_IPV6_CSUM   16  /* Can
checksum TCP/UDP over IPV6 */  
  54. #define NETIF_F_HIGHDMA     32  /* Can DMA to high memory. */  
  55. #define NETIF_F_FRAGLIST    64  /* Scatter/gather IO. */  
  56. #define NETIF_F_HW_VLAN_TX  128 /* Transmit VLAN hw acceleration */  
  57. #define NETIF_F_HW_VLAN_RX  256 /* Receive VLAN hw acceleration */  
  58. #define NETIF_F_HW_VLAN_FILTER  512 /* Receive filtering on VLAN */  
  59. #define NETIF_F_VLAN_CHALLENGED 1024    /* Device cannot handle VLAN packets
*/  
  60. #define NETIF_F_GSO     2048    /* Enable software GSO. */  
  61. #define NETIF_F_LLTX        4096    /* LockLess TX - deprecated.
Please */  
  62.                     /* do not use LLTX in new
drivers */  
  63. #define NETIF_F_NETNS_LOCAL 8192    /* Does not change network namespaces
*/  
  64. #define NETIF_F_GRO     16384   /*
Generic receive offload */  
  65. #define NETIF_F_LRO     32768   /*
large receive offload */  
  66.   
  67.     /* Segmentation offload features */  
  68. #define NETIF_F_GSO_SHIFT   16  
  69. #define NETIF_F_GSO_MASK    0xffff0000  
  70. #define NETIF_F_TSO     (SKB_GSO_TCPV4  NETIF_F_GSO_SHIFT)  
  71. #define NETIF_F_UFO     (SKB_GSO_UDP  NETIF_F_GSO_SHIFT)  
  72. #define NETIF_F_GSO_ROBUST  (SKB_GSO_DODGY  NETIF_F_GSO_SHIFT)  
  73. #define NETIF_F_TSO_ECN     (SKB_GSO_TCP_ECN  NETIF_F_GSO_SHIFT)  
  74. #define NETIF_F_TSO6        (SKB_GSO_TCPV6  NETIF_F_GSO_SHIFT)  
  75.   
  76.     /* List of features with software
fallbacks. */  
  77. #define NETIF_F_GSO_SOFTWARE    (NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6)  
  78.   
  79.   
  80. #define NETIF_F_GEN_CSUM    (NETIF_F_NO_CSUM | NETIF_F_HW_CSUM)  
  81. #define NETIF_F_V4_CSUM     (NETIF_F_GEN_CSUM | NETIF_F_IP_CSUM)  
  82. #define NETIF_F_V6_CSUM     (NETIF_F_GEN_CSUM | NETIF_F_IPV6_CSUM)  
  83. #define NETIF_F_ALL_CSUM    (NETIF_F_V4_CSUM | NETIF_F_V6_CSUM)  
  84.   
  85.     /*
  86.     
* If one device supports one of these features, then enable them
  87.     
* for all in netdev_increment_features.
  88.     
*/  
  89. #define NETIF_F_ONE_FOR_ALL (NETIF_F_GSO_SOFTWARE | NETIF_F_GSO_ROBUST | \  
  90.                  NETIF_F_SG | NETIF_F_HIGHDMA |     \  
  91.                  NETIF_F_FRAGLIST)  
  92.   
  93.     /* Interface index. Unique device
identifier    */  
  94.     int         ifindex;  
  95.     int         iflink;  
  96.   
  97.     struct net_device_stats stats;  
  98.   
  99. #ifdef CONFIG_WIRELESS_EXT  
100.     /* List of functions to handle Wireless
Extensions (instead of ioctl).
101.     
* See  for details. Jean II */  
102.     const struct iw_handler_def *  
wireless_handlers;  
103.     /* Instance data managed by the core of
Wireless Extensions. */  
104.     struct iw_public_data * wireless_data;  
105. #endif  
106.     /* Management operations */  
107.     const struct net_device_ops *netdev_ops;  
108.     const struct ethtool_ops *ethtool_ops;  
109.   
110.     /* Hardware header description */  
111.     const struct header_ops *header_ops;  
112.   
113.     unsigned int        flags;  /* interface flags (a la BSD)   */  
114.     unsigned short      gflags;  
115.         unsigned short          priv_flags; /* Like 'flags' but invisible to userspace. */  
116.     unsigned short      padded; /* How much padding added by alloc_netdev() */  
117.   
118.     unsigned char       operstate; /* RFC2863 operstate */  
119.     unsigned char       link_mode; /* mapping policy to operstate */  
120.   
121.     unsigned        mtu;    /* interface MTU value      */
122.     unsigned short      type;   /* interface hardware type  */  
123.     unsigned short      hard_header_len;    /*
hardware hdr length  */  
124.   
125.     /* extra head- and tailroom the hardware
may need, but not in all cases
126.     
* can this be guaranteed, especially tailroom. Some cases also use
127.     
* LL_MAX_HEADER instead to allocate the skb.
128.     
*/  
129.     unsigned short      needed_headroom;  
130.     unsigned short      needed_tailroom;  
131.   
132.     struct net_device   *master; /* Pointer to master device of a group,
133.                       * which this device is
member of.
134.                       */  
135.   
136.     /* Interface address info. */  
137.     unsigned char       perm_addr[MAX_ADDR_LEN]; /* permanent hw
address */  
138.     unsigned char       addr_len;   /* hardware address length  */  
139.     unsigned short         
dev_id;     /*
for shared network cards */  
140.   
141.     spinlock_t      addr_list_lock;  
142.     struct dev_addr_list   
*uc_list;   /* Secondary unicast mac
addresses */  
143.     int         uc_count;   /* Number of installed
ucasts   */  
144.     int         uc_promisc;  
145.     struct dev_addr_list   
*mc_list;   /* Multicast mac addresses  */  
146.     int         mc_count;   /* Number of installed
mcasts   */  
147.     unsigned int        promiscuity;  
148.     unsigned int        allmulti;  
149.   
150.   
151.     /* Protocol specific pointers */  
152.      
153. #ifdef CONFIG_NET_DSA  
154.     void            *dsa_ptr;   /* dsa specific data */  
155. #endif  
156.     void            *atalk_ptr; /* AppleTalk
link   */
157.     void            *ip_ptr;    /* IPv4 specific data   */   
158.     void                    *dn_ptr;        /* DECnet specific data */  
159.     void                    *ip6_ptr;      
/* IPv6 specific data */  
160.     void            *ec_ptr;    /* Econet specific data */  
161.     void            *ax25_ptr;  /* AX.25 specific data */  
162.     struct wireless_dev *ieee80211_ptr; /* IEEE 802.11 specific data,
163.                            assign before
registering */  
164.   
165. /*
166.  *
Cache line mostly used on receive path (including eth_type_trans())
167.
*/  
168.     unsigned long       last_rx;    /* Time of last Rx  */  
169.     /* Interface address info used in
eth_type_trans() */  
170.     unsigned char       dev_addr[MAX_ADDR_LEN]; /* hw address,
(before bcast  
171.                                because most
packets are unicast) */  
172.   
173.     unsigned char       broadcast[MAX_ADDR_LEN];    /* hw bcast add */  
174.   
175.     struct netdev_queue rx_queue;  
176.   
177.     struct netdev_queue *_tx ____cacheline_aligned_in_smp;  
178.   
179.     /* Number of TX queues allocated at
alloc_netdev_mq() time  */  
180.     unsigned int        num_tx_queues;  
181.   
182.     /* Number of TX queues currently active in
device  */  
183.     unsigned int        real_num_tx_queues;  
184.   
185.     unsigned long       tx_queue_len;   /* Max frames per queue allowed
*/  
186.     spinlock_t      tx_global_lock;  
187. /*
188.  *
One part is mostly used on xmit path (device)
189.
*/  
190.     /* These may be needed for future
network-power-down code. */  
191.     unsigned long       trans_start;    /* Time (in jiffies) of last Tx
*/  
192.   
193.     int         watchdog_timeo; /* used by dev_watchdog() */  
194.     struct timer_list   watchdog_timer;  
195.   
196.     /* Number of references to this device
*/  
197.     atomic_t        refcnt ____cacheline_aligned_in_smp;  
198.   
199.     /* delayed register/unregister */  
200.     struct list_head    todo_list;  
201.     /* device index hash chain */  
202.     struct hlist_node   index_hlist;  
203.   
204.     struct net_device   *link_watch_next;  
205.   
206.     /* register/unregister state machine
*/  
207.     enum { NETREG_UNINITIALIZED=0,
208.            NETREG_REGISTERED,   /* completed register_netdevice
*/  
209.            NETREG_UNREGISTERING,    /* called unregister_netdevice
*/  
210.            NETREG_UNREGISTERED, /* completed unregister todo */  
211.            NETREG_RELEASED,     /* called free_netdev */  
212.            NETREG_DUMMY,        /* dummy device for NAPI
poll */  
213.     } reg_state;  
214.   
215.     /* Called from unregister, can be used to
call free_netdev */  
216.     void (*destructor)(struct net_device *dev);  
217.   
218. #ifdef CONFIG_NETPOLL  
219.     struct netpoll_info *npinfo;  
220. #endif  
221.   
222. #ifdef CONFIG_NET_NS  
223.     /* Network namespace this network device
is inside */  
224.     struct net      *nd_net;  
225. #endif  
226.   
227.     /* mid-layer private */  
228.     void            *ml_priv;  
229.   
230.     /* bridge stuff */  
231.     struct net_bridge_port
*br_port;  
232.     /* macvlan */  
233.     struct macvlan_port *macvlan_port;  
234.     /* GARP */
235.     struct garp_port    *<span style="font-size: 10pt; font-fa

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/98073/showart_2056591.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP