Linux 网卡驱动学习(三)(net_device 等数据结构)

【摘要】前文对网络驱动例子进行一个简单的梳理总结,本文贴出 net_device 的数据结构以及一些驱动中常用的数据结构。

1、网络设备驱动结构

1)、网络协议接口层向网络层协议提供提供统一的数据包收发接口,不论上层协议为ARP还是IP,都通过dev_queue_xmit()函数发送数据,并通过netif_rx()函数接受数据。这一层的存在使得上层协议独立于具体的设备。
2)、网络设备接口层向协议接口层提供统一的用于描述具体网络设备属性和操作的结构体net_device,该结构体是设备驱动功能层中各函数的容器。实际上,网络设备接口层从宏观上规划了具体操作硬件的设备驱动功能层的结构。
3)、设备驱动功能层各函数是网络设备接口层net_device数据结构的具体成员,是驱使网络设备硬件完成相应动作的程序,他通过hard_start_xmit()函数启动发送操作,并通过网络设备上的中断触发接受操作。
4)、网络设备与媒介层是完成数据包发送和接受的物理实体,包括网络适配器和具体的传输媒介,网络适配器被驱动功能层中的函数物理上驱动。对于Linux系统而言,网络设备和媒介都可以是虚拟的。

2、网卡驱动中重要的数据结构

  1. struct softnet_data  
  2. {  
  3.     int            throttle;  
  4.     int            cng_level;  
  5.     int            avg_blog;  
  6.     struct sk_buff_head    input_pkt_queue;  
  7.     struct list_head    poll_list;  
  8.     struct net_device    *output_queue;  
  9.     struct sk_buff        *completion_queue;  
  10.   
  11.     struct net_device    backlog_dev;    /* Sorry. 8) */  
  12. };  
  13.   
  14.   
  15.   
  16. struct packet_type {  
  17.     unsigned short        type;    /* This is really htons(ether_type).    */  
  18.     struct net_device        *dev;    /* NULL is wildcarded here        */  
  19.     int            (*func) (struct sk_buff *, struct net_device *,  
  20.                      struct packet_type *);  
  21.     void            *af_packet_priv;  
  22.     struct list_head    list;  
  23. };  
  24.   
  25.   
  26. struct netif_rx_stats  
  27. {  
  28.     unsigned total;  
  29.     unsigned dropped;  
  30.     unsigned time_squeeze;  
  31.     unsigned throttled;  
  32.     unsigned fastroute_hit;  
  33.     unsigned fastroute_success;  
  34.     unsigned fastroute_defer;  
  35.     unsigned fastroute_deferred_out;  
  36.     unsigned fastroute_latency_reduction;  
  37.     unsigned cpu_collision;  
  38. };  
  39.   
  40.   
  41. struct net_device_stats  
  42. {  
  43.     unsigned long    rx_packets;        /* total packets received    */  
  44.     unsigned long    tx_packets;        /* total packets transmitted    */  
  45.     unsigned long    rx_bytes;        /* total bytes received     */  
  46.     unsigned long    tx_bytes;        /* total bytes transmitted    */  
  47.     unsigned long    rx_errors;        /* bad packets received        */  
  48.     unsigned long    tx_errors;        /* packet transmit problems    */  
  49.     unsigned long    rx_dropped;        /* no space in linux buffers    */  
  50.     unsigned long    tx_dropped;        /* no space available in linux    */  
  51.     unsigned long    multicast;        /* multicast packets received    */  
  52.     unsigned long    collisions;  
  53.   
  54.     /* detailed rx_errors: */  
  55.     unsigned long    rx_length_errors;  
  56.     unsigned long    rx_over_errors;        /* receiver ring buff overflow    */  
  57.     unsigned long    rx_crc_errors;        /* recved pkt with crc error    */  
  58.     unsigned long    rx_frame_errors;    /* recv'd frame alignment error */  
  59.     unsigned long    rx_fifo_errors;        /* recv'r fifo overrun        */  
  60.     unsigned long    rx_missed_errors;    /* receiver missed packet    */  
  61.   
  62.     /* detailed tx_errors */  
  63.     unsigned long    tx_aborted_errors;  
  64.     unsigned long    tx_carrier_errors;  
  65.     unsigned long    tx_fifo_errors;  
  66.     unsigned long    tx_heartbeat_errors;  
  67.     unsigned long    tx_window_errors;  
  68.       
  69.     /* for cslip etc */  
  70.     unsigned long    rx_compressed;  
  71.     unsigned long    tx_compressed;  
  72. };  
  73.   
  74.   
  75. /* Media selection options. */  
  76. enum {  
  77.         IF_PORT_UNKNOWN = 0,  
  78.         IF_PORT_10BASE2,  
  79.         IF_PORT_10BASET,  
  80.         IF_PORT_AUI,  
  81.         IF_PORT_100BASET,  
  82.         IF_PORT_100BASETX,  
  83.         IF_PORT_100BASEFX  
  84. };  
  85.   
  86.   
  87. struct net_device  
  88. {  
  89.   
  90.     /* 
  91.      * This is the first field of the "visible" part of this structure 
  92.      * (i.e. as seen by users in the "Space.c" file).  It is the name 
  93.      * the interface. 
  94.      */  
  95.     char            name[IFNAMSIZ];      //eth0 eth1 ... ethn  
  96.   
  97.     /* 
  98.      *    I/O specific fields 
  99.      *    FIXME: Merge these and struct ifmap into one 
  100.      */  
  101.     unsigned long        mem_end;    /* shared mem end    */  
  102.     unsigned long        mem_start;    /* shared mem start    */  
  103.     unsigned long        base_addr;    /* device I/O address    */ //网络接口的I/O基地址,由驱动在设备探测时赋值 ifconfig可以显示或  
  104.                                         修改当前值,该字段可以在系统启动时在内核命令行中显式赋值,或者  
  105.                                         在模块加载时赋值。这个成员一般不被引用  
  106.     unsigned int        irq;        /* device IRQ number    */    //网络设备使用的中断号。irq值常常在网络设备启动时加载设置,  
  107.                                             并且在后来由ifconfig打印出来。  
  108.   
  109.     /* 
  110.      *    Some hardware also needs these fields, but they are not 
  111.      *    part of the usual set specified in Space.c. 
  112.      */  
  113.   
  114.     unsigned char        if_port;    /* Selectable AUI, TP,..*/   //多端口设备中使用的端口。该成员在同轴线(IF_PORT_10BASE2)和  
  115.                                         //双绞线(IF_PORT_100BASET)以太网连接时使用  
  116.     unsigned char        dma;        /* DMA channel        */     //在某些外设总线时有意义,如ISA总线。它不在设备驱动自身以外使用  
  117.   
  118.     unsigned long        state;         //网络设备和网络适配器的状态信息  
  119.   
  120.     struct net_device    *next;        //下一个struct net_device Linux中所有网络设备都以dev_base指针开头的单线行链表管理  
  121.       
  122.     /* The device initialization function. Called only once. */  
  123.     int            (*init)(struct net_device *dev);    用来搜索并初始化网络设备。该方法负责寻找并初始化当前类型的网络适配器。首选必须创建net_device结构并将网络设备和网络驱动程序的数据(驱动相关的)填充进去。其次,register_netdevice()注册网络设备  
  124.   
  125.   
  126.     /* ------- Fields preinitialized in Space.c finish here ------- */  
  127.   
  128.     struct net_device    *next_sched;  
  129.   
  130.     /* Interface index. Unique device identifier    */  
  131.     int            ifindex;  
  132.     int            iflink;  
  133.   
  134.   
  135.     struct net_device_stats* (*get_stats)(struct net_device *dev);  应用程序需要获取网络接口的统计信息时会调用这个方法。例如,在运行ifconfig或netstat -i时,会调用该方法  
  136.     struct iw_statistics*    (*get_wireless_stats)(struct net_device *dev);  
  137.   
  138.     /* List of functions to handle Wireless Extensions (instead of ioctl). 
  139.      * See <net/iw_handler.h> for details. Jean II */  
  140.     const struct iw_handler_def *    wireless_handlers;  
  141.     /* Instance data managed by the core of Wireless Extensions. */  
  142.     struct iw_public_data *    wireless_data;  
  143.   
  144.     struct ethtool_ops *ethtool_ops;  
  145.   
  146.     /* 
  147.      * This marks the end of the "visible" part of the structure. All 
  148.      * fields hereafter are internal to the system, and may change at 
  149.      * will (read: may be cleaned up at will). 
  150.      */  
  151.   
  152.     /* These may be needed for future network-power-down code. */  
  153.     unsigned long        trans_start;    /* Time (in jiffies) of last Tx    */  
  154.     unsigned long        last_rx;    /* Time of last Rx    */  
  155.   
  156.     unsigned short        flags;    /* interface flags (a la BSD)    */  
  157.     unsigned short        gflags;  
  158.         unsigned short          priv_flags; /* Like 'flags' but invisible to userspace. */  
  159.         unsigned short          unused_alignment_fixer; /* Because we need priv_flags, 
  160.                                                          * and we want to be 32-bit aligned. 
  161.                                                          */  
  162.   
  163.     unsigned        mtu;    /* interface MTU value        */   //最大传输单元。它指定链路层每帧有效载荷最大长度。网络层各协议必须  
  164.                                         考虑该值,以确保不会向网络适配器发送多余的字节,以太网1500,通  
  165.                                         过ifconfig命令可改变  
  166.     unsigned short        type;    /* interface hardware type    */     //指定了网络适配器的硬件类型。这个成员由ARP用来决定网络适配器  
  167.                                         支持的硬件地址。对以太网接口一般由ether_setup()函数设置其值为  
  168.                                         ARPHRD_ETHER  
  169.   
  170.     unsigned short        hard_header_len;    /* hardware hdr length    */  //指定链路层数据帧包头长度。对于以太网接口为14  
  171.     void            *priv;    /* pointer to private data    */  
  172.   
  173.     struct net_device    *master; /* Pointer to master device of a group, 
  174.                       * which this device is member of. 
  175.                       */  
  176.   
  177.     /* Interface address info. */  
  178.     unsigned char        broadcast[MAX_ADDR_LEN];    /* hw bcast add    */    //广播地址         
  179.     /*以太网地址长度是6个字节(我们指的是接口板的硬件ID),广播地址由6个0xff字节组成。这些字段一般由ether_setup()函数设置。驱动程序必须以特定于设备的方式从接口板读出,并复制到dev_addr结构。网络设备的硬件地址用来产生正确的以太网头*/  
  180.     unsigned char        dev_addr[MAX_ADDR_LEN];    /* hw address    */               //存放设备硬件地址  
  181.     unsigned char        addr_len;    /* hardware address length    */       //硬件(MAC)地址长度  
  182.   
  183.     struct dev_mc_list    *mc_list;    /* Multicast mac addresses    */     /*指向具有多播的第二层地址的线性表。当网络适配器收集到具有包含在dev_mc_list中目标地址后,网络适配器必须将包传递给更高层。驱动程序中方法set_multicast_list用来将该列表中的地址传递给网络适配器。该网络适配器的硬件过滤器(如果有)负责只将与该计算机有关的包传递给内核 */  
  184.   
  185.     int            mc_count;    /* Number of installed mcasts    */  //dev_mc_list包含的地址数量  
  186.     int            promiscuity;  
  187.     int            allmulti;  
  188.   
  189. /*下面两个变量用来发现适配器在发送包时遇到的问题。 
  190.     int            watchdog_timeo;         
  191.     struct timer_list    watchdog_timer;  /*在网络设备启动时打开,每经过watch_timeo时间后立即被调用。处理程序dev_watchdog()检查从上一次(存储在stans_start中)包传输后是否经过watch_timeo单位长度的时间。如果是,那么上一个包的传输中出现问题,必须检查网络适配器。要检查网络适配器,需要调用驱动函数tx_timeout()。如果从上次传输开始还没有经过足够长的时间,那么除了watchdog计时器启动之外没有发生其他网络事件*/  
  192.   
  193.     /* Protocol specific pointers */  
  194. /*指向网络适配器的第三层协议的信息。如果网络设备被设置为Internet协议,那么ip_ptr指向in_device类型的结构,它管理有关的IP实例的信息和配置参数。例如in_device结构管理包含网络设备IP地址列表,包含多播组活动IP列表和ARP协议参数等*/  
  195.       
  196.     void             *atalk_ptr;    /* AppleTalk link     */  
  197.     void            *ip_ptr;    /* IPv4 specific data    */    
  198.     void                    *dn_ptr;        /* DECnet specific data */  
  199.     void                    *ip6_ptr;       /* IPv6 specific data */  
  200.     void            *ec_ptr;    /* Econet specific data    */  
  201.     void            *ax25_ptr;    /* AX.25 specific data */  
  202.   
  203.     struct list_head    poll_list;    /* Link to poll list    */  
  204.     int            quota;  
  205.     int            weight;  
  206.   
  207.     struct Qdisc        *qdisc;  
  208.     struct Qdisc        *qdisc_sleeping;  
  209.     struct Qdisc        *qdisc_ingress;  
  210.     struct list_head    qdisc_list;   
  211.     unsigned long        tx_queue_len;    /* Max frames per queue allowed */    //该字段表示指定了网络设备发送队列中可以排列的最大帧数  
  212.                                             这个值有ether_setup()设置为100.不要将tx_queue_len  
  213.                                             与网络适配器的缓冲区想混淆。通常网络适配器有额外的环形  
  214.                                             缓冲区,大小为16或32个包大小  
  215.   
  216.     /* ingress path synchronizer */  
  217.     spinlock_t        ingress_lock;  
  218.     /* hard_start_xmit synchronizer */  
  219.     spinlock_t        xmit_lock;  
  220.     /* cpu id of processor entered to hard_start_xmit or -1, 
  221.        if nobody entered there. 
  222.      */  
  223.     int            xmit_lock_owner;  
  224.     /* device queue lock */  
  225.     spinlock_t        queue_lock;  
  226.     /* Number of references to this device */  
  227.     atomic_t        refcnt;  
  228.     /* delayed register/unregister */  
  229.     struct list_head    todo_list;  
  230.     /* device name hash chain */  
  231.     struct hlist_node    name_hlist;  
  232.     /* device index hash chain */  
  233.     struct hlist_node    index_hlist;  
  234.   
  235.     /* register/unregister state machine */  
  236.     enum { NETREG_UNINITIALIZED=0,  
  237.            NETREG_REGISTERING,    /* called register_netdevice */  
  238.            NETREG_REGISTERED,    /* completed register todo */  
  239.            NETREG_UNREGISTERING,    /* called unregister_netdevice */  
  240.            NETREG_UNREGISTERED,    /* completed unregister todo */  
  241.            NETREG_RELEASED,        /* called free_netdev */  
  242.     } reg_state;  
  243.   
  244.     /* Net device features */  
  245.     int            features;  
  246. #define NETIF_F_SG        1    /* Scatter/gather IO. */  
  247. #define NETIF_F_IP_CSUM        2    /* Can checksum only TCP/UDP over IPv4. */  
  248. #define NETIF_F_NO_CSUM        4    /* Does not require checksum. F.e. loopack. */  
  249. #define NETIF_F_HW_CSUM        8    /* Can checksum all the packets. */  
  250. #define NETIF_F_HIGHDMA        32    /* Can DMA to high memory. */  
  251. #define NETIF_F_FRAGLIST    64    /* Scatter/gather IO. */  
  252. #define NETIF_F_HW_VLAN_TX    128    /* Transmit VLAN hw acceleration */  
  253. #define NETIF_F_HW_VLAN_RX    256    /* Receive VLAN hw acceleration */  
  254. #define NETIF_F_HW_VLAN_FILTER    512    /* Receive filtering on VLAN */  
  255. #define NETIF_F_VLAN_CHALLENGED    1024    /* Device cannot handle VLAN packets */  
  256. #define NETIF_F_TSO        2048    /* Can offload TCP/IP segmentation */  
  257. #define NETIF_F_LLTX        4096    /* LockLess TX */  
  258.   
  259.     /* Called after device is detached from network. */  
  260.     void            (*uninit)(struct net_device *dev); 用来注销网络设备,该方法用来执行驱动程序相关的函数,这些函数在删除网络设备时也是必须的。目前没有驱动程序使用该方法  
  261.   
  262.     /* Called after last user reference disappears. */  
  263.     void            (*destructor)(struct net_device *dev);  
  264.   
  265.     /* Pointers to interface service routines.    */  
  266.     int            (*open)(struct net_device *dev);    打开一个已经命名的网络设备。可以使用ifconfig命令激活网络设备,在激活过程中,open方法应当注册它需要的系统资源(I/O口,IRQ,DMA,等等),以及进行其他的网络设备要求  
  267.     int            (*stop)(struct net_device *dev);  停止网络适配器的活动并释放相关资源,此后网络设备不能活动  
  268.     int            (*hard_start_xmit) (struct sk_buff *skb,   
  269.                             struct net_device *dev); 在网络设备上发送数据包的方法。完整的报文(协议头和所有其他数据)包含在一个socket缓冲区(sk_buff)结构中。数据包如果成功发送到网络适配器该函数返回0,否则返回1  
  270. #define HAVE_NETDEV_POLL  
  271.     int            (*poll) (struct net_device *dev, int *quota);  
  272.     int            (*hard_header) (struct sk_buff *skb,  
  273.                         struct net_device *dev,  
  274.                         unsigned short type,  
  275.                         void *daddr,  
  276.                         void *saddr,  
  277.                         unsigned len);  用先前提取到的源和目的硬件地址来建立硬件头的函数(在hard_start_xmit 前调用)。它的工作是将传给它的参数信息组织成一个合适的特定于设备的硬件头  
  278.     int            (*rebuild_header)(struct sk_buff *skb);  用来在ARP解析完成后、报文发送前,重建硬件头的函数  
  279. #define HAVE_MULTICAST               
  280.     void            (*set_multicast_list)(struct net_device *dev);   将多播MAC地址列表传递给网络适配器,适配器就可以根据这些地址接收包  
  281. #define HAVE_SET_MAC_ADDR             
  282.     int            (*set_mac_address)(struct net_device *dev,  
  283.                            void *addr);    改变网络设备的硬件地址(MAC地址)  
  284. #define HAVE_PRIVATE_IOCTL  
  285.     int            (*do_ioctl)(struct net_device *dev,  
  286.                         struct ifreq *ifr, int cmd);  
  287. #define HAVE_SET_CONFIG  
  288.     int            (*set_config)(struct net_device *dev,  
  289.                           struct ifmap *map);  
  290. #define HAVE_HEADER_CACHE  
  291.     int            (*hard_header_cache)(struct neighbour *neigh,  
  292.                              struct hh_cache *hh);  
  293.     void            (*header_cache_update)(struct hh_cache *hh,  
  294.                                struct net_device *dev,  
  295.                                unsigned char *  haddr);  在响应一个变化中,更新hh_cache结构中的目的地址方法  
  296. #define HAVE_CHANGE_MTU  
  297.     int            (*change_mtu)(struct net_device *dev, int new_mtu);  改变网络设备最大传输单元(MTU)函数  
  298.   
  299. #define HAVE_TX_TIMEOUT  
  300.     void            (*tx_timeout) (struct net_device *dev);  网络驱动程序代码没有在一个合理的时间内将一个报文发送完成时会调用该方法,报文没有被及时发送的原因可能是丢失一个中断或某个接口被锁。此时该函数处理这个问题并恢复报文发送  
  301.   
  302.     void            (*vlan_rx_register)(struct net_device *dev,  
  303.                             struct vlan_group *grp);  
  304.     void            (*vlan_rx_add_vid)(struct net_device *dev,  
  305.                            unsigned short vid);  
  306.     void            (*vlan_rx_kill_vid)(struct net_device *dev,  
  307.                             unsigned short vid);  
  308.   
  309.     int            (*hard_header_parse)(struct sk_buff *skb,  
  310.                              unsigned char *haddr);  该方法完成的工作包括从skb中的报文中抽取源地址,复制到haddr的缓冲区中。函数的返回值是地址的长度信息  
  311.     int            (*neigh_setup)(struct net_device *dev, struct neigh_parms *);  
  312.     int            (*accept_fastpath)(struct net_device *, struct dst_entry*);  
  313. #ifdef CONFIG_NETPOLL  
  314.     int            netpoll_rx;  
  315. #endif  
  316. #ifdef CONFIG_NET_POLL_CONTROLLER  
  317.     void                    (*poll_controller)(struct net_device *dev);  
  318. #endif  
  319.   
  320.     /* bridge stuff */  
  321.     struct net_bridge_port    *br_port;  
  322.   
  323. #ifdef CONFIG_NET_DIVERT  
  324.     /* this will get initialized at each interface type init routine */  
  325.     struct divert_blk    *divert;  
  326. #endif /* CONFIG_NET_DIVERT */  
  327.   
  328.     /* class/net/name entry */  
  329.     struct class_device    class_dev;  
  330.     /* how much padding had been added by alloc_netdev() */  
  331.     int padded;  
  332. };  
  333.   
  334.   
  335.   
  336. struct netdev_boot_setup {  
  337.     char name[IFNAMSIZ];  
  338.     struct ifmap map;  
  339. };  
  340.   
  341.   
  342. struct hh_cache  
  343. {  
  344.     struct hh_cache *hh_next;    /* Next entry                 */  
  345.     atomic_t    hh_refcnt;    /* number of users                   */  
  346.     unsigned short  hh_type;    /* protocol identifier, f.e ETH_P_IP 
  347.                                          *  NOTE:  For VLANs, this will be the 
  348.                                          *  encapuslated type. --BLG 
  349.                                          */  
  350.     int        hh_len;        /* length of header */  
  351.     int        (*hh_output)(struct sk_buff *skb);  
  352.     rwlock_t    hh_lock;  
  353.   
  354.     /* cached hardware header; allow for machine alignment needs.        */  
  355. #define HH_DATA_MOD    16  
  356. #define HH_DATA_OFF(__len) \  
  357.     (HH_DATA_MOD - ((__len) & (HH_DATA_MOD - 1)))  
  358. #define HH_DATA_ALIGN(__len) \  
  359.     (((__len)+(HH_DATA_MOD-1))&~(HH_DATA_MOD - 1))  
  360.     unsigned long    hh_data[HH_DATA_ALIGN(LL_MAX_HEADER) / sizeof(long)];  
  361. };  
  362.   
  363.   
  364. struct dev_mc_list  
  365. {      
  366.     struct dev_mc_list    *next;  
  367.     __u8            dmi_addr[MAX_ADDR_LEN];  
  368.     unsigned char        dmi_addrlen;  
  369.     int            dmi_users;  
  370.     int            dmi_gusers;  
  371. };  
  372.   
  373.   
  374. struct sk_buff_head {  
  375.     /* These two members must be first. */  
  376.     struct sk_buff    *next;  
  377.     struct sk_buff    *prev;  
  378.   
  379.     __u32        qlen;  
  380.     spinlock_t    lock;  
  381. };  
  382.   
  383. struct sk_buff;  
  384.   
  385. /* To allow 64K frame to be packed as single skb without frag_list */  
  386. #define MAX_SKB_FRAGS (65536/PAGE_SIZE + 2)  
  387.   
  388. typedef struct skb_frag_struct skb_frag_t;  
  389.   
  390. struct skb_frag_struct {  
  391.     struct page *page;  
  392.     __u16 page_offset;  
  393.     __u16 size;  
  394. };  
  395.   
  396.   
  397. struct sk_buff {  
  398.     /* These two members must be first. */  
  399.     struct sk_buff        *next;  
  400.     struct sk_buff        *prev;   //双向链表指针  
  401.   
  402.     struct sk_buff_head    *list;  指向套接字缓存在队列中的当前位置  
  403.     struct sock        *sk;  指向创建报文的socket  
  404.     struct timeval        stamp;   报文到达Linux系统的时间  
  405.     struct net_device    *dev;  表明套接字缓存当前操作所在的网络设备。网络路由器被确定下来后,dev就指向报文离开计算机时经过的网络适配器。知道报文的输出适配器已知之前,dev都指向输入适配器  
  406.     struct net_device    *input_dev;  
  407.     struct net_device    *real_dev;  
  408.   
  409.     union {  
  410.         struct tcphdr    *th;  
  411.         struct udphdr    *uh;  
  412.         struct icmphdr    *icmph;  
  413.         struct igmphdr    *igmph;  
  414.         struct iphdr    *ipiph;  
  415.         struct ipv6hdr    *ipv6h;  
  416.         unsigned char    *raw;  
  417.     } h;    传输层报文帧头的指针  
  418.   
  419.     union {  
  420.         struct iphdr    *iph;  
  421.         struct ipv6hdr    *ipv6h;  
  422.         struct arphdr    *arph;  
  423.         unsigned char    *raw;  
  424.     } nh; 网络层报文帧头的指针  
  425.   
  426.     union {  
  427.           unsigned char     *raw;  
  428.     } mac; MAC层报文帧头的指针  
  429.   
  430.     struct  dst_entry    *dst;   指向路由高速缓存中的一条记录,它包含着有关报文进一步前进的路由信息  
  431.     struct    sec_path    *sp;  
  432.   
  433.     /* 
  434.      * This is the control buffer. It is free to use for every 
  435.      * layer. Please put your private variables there. If you 
  436.      * want to keep them across layers you have to do a skb_clone() 
  437.      * first. This is owned by whoever has the skb queued ATM. 
  438.      */  
  439.     char            cb[40];  
  440.   
  441.     unsigned int        len,            指明套接字缓存所代表的报文长度,这里只考虑内核可访问的数据。在以太网报文中两个MAC地址和类型/长度域被考虑其中。其他的域(报头、链接和检验)以后再在网络适配器中进行添加  
  442.                 data_len,  
  443.                 mac_len,  
  444.                 csum;  
  445.     unsigned char        local_df,  
  446.                 cloned,  
  447.                 pkt_type,        报文的类型  
  448.                 ip_summed;  
  449.     __u32            priority;  
  450.     unsigned short        protocol,  
  451.                 security;  
  452.   
  453.     void            (*destructor)(struct sk_buff *skb);  
  454. #ifdef CONFIG_NETFILTER  
  455.         unsigned long        nfmark;  
  456.     __u32            nfcache;  
  457.     __u32            nfctinfo;  
  458.     struct nf_conntrack    *nfct;  
  459. #ifdef CONFIG_NETFILTER_DEBUG  
  460.         unsigned int        nf_debug;  
  461. #endif  
  462. #ifdef CONFIG_BRIDGE_NETFILTER  
  463.     struct nf_bridge_info    *nf_bridge;  
  464. #endif  
  465. #endif /* CONFIG_NETFILTER */  
  466. #if defined(CONFIG_HIPPI)  
  467.     union {  
  468.         __u32        ifield;  
  469.     } private;  
  470. #endif  
  471. #ifdef CONFIG_NET_SCHED  
  472.        __u32            tc_index;        /* traffic control index */  
  473. #ifdef CONFIG_NET_CLS_ACT  
  474.     __u32           tc_verd;               /* traffic control verdict */  
  475.     __u32           tc_classid;            /* traffic control classid */  
  476. #endif  
  477.   
  478. #endif  
  479.   
  480.   
  481.     /* These elements must be at the end, see alloc_skb() for details.  */  
  482.     unsigned int        truesize;  
  483.     atomic_t        users;  
  484.     unsigned char        *head,    
  485.                 *data,  
  486.                 *tail,  
  487.                 *end;  
  488. };  
  489.   
  490.   
  491. struct skb_shared_info {  
  492.     atomic_t    dataref;  
  493.     unsigned int    nr_frags;  
  494.     unsigned short    tso_size;  
  495.     unsigned short    tso_segs;  
  496.     struct sk_buff    *frag_list;  
  497.     skb_frag_t    frags[MAX_SKB_FRAGS];  
  498. };  
  499.   
  500.   
  501. struct skb_iter {  
  502.     /* Iteration functions set these */  
  503.     unsigned char *data;  
  504.     unsigned int len;  
  505.   
  506.     /* Private to iteration */  
  507.     unsigned int nextfrag;  
  508.     struct sk_buff *fraglist;  
  509. };  
  510.   
  511.   
  512.   
  513. #ifdef CONFIG_NETFILTER  
  514. struct nf_conntrack {  
  515.     atomic_t use;  
  516.     void (*destroy)(struct nf_conntrack *);  
  517. };  
  518.   
  519. #ifdef CONFIG_BRIDGE_NETFILTER  
  520. struct nf_bridge_info {  
  521.     atomic_t use;  
  522.     struct net_device *physindev;  
  523.     struct net_device *physoutdev;  
  524. #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)  
  525.     struct net_device *netoutdev;  
  526. #endif  
  527.     unsigned int mask;  
  528.     unsigned long data[32 / sizeof(unsigned long)];  
  529. }; 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值