net_device结构体,定义在include/linux/netdevice.h中,这是一个很复杂的结构体,先把代码清单列出来,再用到的过程中,逐步分析,最后来这里做个总结。
下面的代码是linux-2.6.38中的。
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 * This is the first field of the "visible" part of this structure
15 * (i.e. as seen by users in the "Space.c" file). It is the name
16 * of the interface.
17 */
18 char name[IFNAMSIZ];
19
20 struct pm_qos_request_list pm_qos_req;
21
22 /* device name hash chain */
23 struct hlist_node name_hlist;
24 /* snmp alias */
25 char *ifalias;
26
27 /*
28 * I/O specific fields
29 * FIXME: Merge these and struct ifmap into one
30 */
31 unsigned long mem_end; /* shared mem end */
32 unsigned long mem_start; /* shared mem start */
33 unsigned long base_addr; /* device I/O address */
34 unsigned int irq; /* device IRQ number */
35
36 /*
37 * Some hardware also needs these fields, but they are not
38 * part of the usual set specified in Space.c.
39 */
40
41 unsigned char if_port; /* Selectable AUI, TP,..*/
42 unsigned char dma; /* DMA channel */
43
44 unsigned long state;
45
46 struct list_head dev_list;
47 struct list_head napi_list;
48 struct list_head unreg_list;
49
50 /* Net device features */
51 unsigned long features;
52 #define NETIF_F_SG 1 /* Scatter/gather IO. */
53 #define NETIF_F_IP_CSUM 2 /* Can checksum TCP/UDP over IPv4. */
54 #define NETIF_F_NO_CSUM 4 /* Does not require checksum. F.e. loopack. */
55 #define NETIF_F_HW_CSUM 8 /* Can checksum all the packets. */
56 #define NETIF_F_IPV6_CSUM 16 /* Can checksum TCP/UDP over IPV6 */
57 #define NETIF_F_HIGHDMA 32 /* Can DMA to high memory. */
58 #define NETIF_F_FRAGLIST 64 /* Scatter/gather IO. */
59 #define NETIF_F_HW_VLAN_TX 128 /* Transmit VLAN hw acceleration */
60 #define NETIF_F_HW_VLAN_RX 256 /* Receive VLAN hw acceleration */
61 #define NETIF_F_HW_VLAN_FILTER 512 /* Receive filtering on VLAN */
62 #define NETIF_F_VLAN_CHALLENGED 1024 /* Device cannot handle VLAN packets */
63 #define NETIF_F_GSO 2048 /* Enable software GSO. */
64 #define NETIF_F_LLTX 4096 /* LockLess TX - deprecated. Please */
65 /* do not use LLTX in new drivers */
66 #define NETIF_F_NETNS_LOCAL 8192 /* Does not change network namespaces */
67 #define NETIF_F_GRO 16384 /* Generic receive offload */