Linux skbuff注释笔记

SKB结构定义   /usr/src/linux/include/linux/skbuff.h

sk_buff_head:
1 struct sk_buff_head {            //SKB的头结点
2     /* These two members must be first. */
3     struct sk_buff    *next;     
4     struct sk_buff    *prev;
5 
6     __u32        qlen;           //队列长度
7     spinlock_t    lock;          //自旋锁
8 };

 

sk_buff:
/** 
 *    struct sk_buff - socket buffer
 *    @next: Next buffer in list
 *    @prev: Previous buffer in list
 *    @sk: Socket we are owned by
 *    @tstamp: Time we arrived
 *    @dev: Device we arrived on/are leaving by
 *    @input_dev: Device we arrived on
 *    @h: Transport layer header
 *    @nh: Network layer header
 *    @mac: Link layer header
 *    @dst: destination entry
 *    @sp: the security path, used for xfrm
 *    @cb: Control buffer. Free for use by every layer. Put private vars here
 *    @len: Length of actual data
 *    @data_len: Data length
 *    @mac_len: Length of link layer header
 *    @csum: Checksum
 *    @local_df: allow local fragmentation
 *    @cloned: Head may be cloned (check refcnt to be sure)
 *    @nohdr: Payload reference only, must not modify header
 *    @pkt_type: Packet class
 *    @fclone: skbuff clone status
 *    @ip_summed: Driver fed us an IP checksum
 *    @priority: Packet queueing priority
 *    @users: User count - see {datagram,tcp}.c
 *    @protocol: Packet protocol from driver
 *    @truesize: Buffer size 
 *    @head: Head of buffer
 *    @data: Data head pointer
 *    @tail: Tail pointer
 *    @end: End pointer
 *    @destructor: Destruct function
 *    @mark: Generic packet mark
 *    @nfct: Associated connection, if any
 *    @ipvs_property: skbuff is owned by ipvs
 *    @nfctinfo: Relationship of this skb to the connection
 *    @nfct_reasm: netfilter conntrack re-assembly pointer
 *    @nf_bridge: Saved data about a bridged frame - see br_netfilter.c
 *    @tc_index: Traffic control index
 *    @tc_verd: traffic control verdict
 *    @dma_cookie: a cookie to one of several possible DMA operations
 *        done by skb DMA functions
 *    @secmark: security marking
 */

struct sk_buff {
    /* These two members must be first. */
    struct sk_buff        *next;
    struct sk_buff        *prev;

    struct sock        *sk;              //宿主传输控制块,本地发送或本地接收时有效,转发时为空
    struct skb_timeval    tstamp;        //时间戳
    struct net_device    *dev;           //网络设备指针
    struct net_device    *input_dev;     //接收报文的原始网络设备,包为本地生成时为空,用于流量控制

    union {                              //指向四层协议首部,包含的数据结构表示在这一层上可以解析的协议
        struct tcphdr    *th;
        struct udphdr    *uh;
        struct icmphdr    *icmph;
        struct igmphdr    *igmph;
        struct iphdr    *ipiph;
        struct ipv6hdr    *ipv6h;
        unsigned char    *raw;           // 用于初始化
    } h;                                 

    union {                              //指向三层协议首部
        struct iphdr    *iph;
        struct ipv6hdr    *ipv6h;
        struct arphdr    *arph;
        unsigned char    *raw;
    } nh;

    union {                              //指向二层协议首部
          unsigned char     *raw;
    } mac;

    struct  dst_entry    *dst;           //目的路由缓存
    struct    sec_path    *sp;           //IPSec协议用来跟踪传输的信息

    /*
     * This is the control buffer. It is free to use for every
     * layer. Please put your private variables there. If you
     * want to keep them across layers you have to do a skb_clone()
     * first. This is owned by whoever has the skb queued ATM.
     */
    char            cb[48];           //信息控制块,存储每层自己的私有信息

    unsigned int        len,          //数据部分长度,包含首部长度
                data_len,             //SG类型和FRAGLIST类型聚合分散I/O存储区中的数据长度
                mac_len;              //数据链路层首部长度
    union {
        __wsum        csum;           //校验状态为CHECKSUM_NONE时,存放所负载数据报的数据部分校验和
        __u32        csum_offset;     //校验状态为CHECKSUM_PARTIAL时,记录传输层首部中的校验和字段的偏移
    };
    __u32            priority;        //发送或转发数据包QoS类别,
    __u8            local_df:1,       //表示此SKB在本地允许分片
                cloned:1,             //标记所属SKB是否被克隆
                ip_summed:2,          //标记传输层校验和的状态
                nohdr:1,              //标识payload是否被单独引用
                nfctinfo:3;           //被防火墙使用
    __u8            pkt_type:3,       //帧类型
                fclone:2,             //当前克隆状态
                ipvs_property:1;
    __be16            protocol;       //链路层协议类型

    void            (*destructor)(struct sk_buff *skb);           //析构函数指针,释放时调用,没有宿主传输控制块时为空
#ifdef CONFIG_NETFILTER
    struct nf_conntrack    *nfct;                                 //被防火墙使用
#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
    struct sk_buff        *nfct_reasm;
#endif
#ifdef CONFIG_BRIDGE_NETFILTER
    struct nf_bridge_info    *nf_bridge;                          //被防火墙使用
#endif
#endif /* CONFIG_NETFILTER */
#ifdef CONFIG_NET_SCHED
    __u16            tc_index;    /* traffic control index 流量控制*/
#ifdef CONFIG_NET_CLS_ACT
    __u16            tc_verd;    /* traffic control verdict */
#endif
#endif
#ifdef CONFIG_NET_DMA
    dma_cookie_t        dma_cookie;
#endif
#ifdef CONFIG_NETWORK_SECMARK
    __u32            secmark;
#endif

    __u32            mark;

    /* These elements must be at the end, see alloc_skb() for details.  */
    unsigned int        truesize;        //缓存区总长度
    atomic_t        users;               //引用计数,标识有多少实体引用SKB,为零时释放
    unsigned char        *head,          //指向缓存区头
                *data,                   //指向数据头
                *tail,                   //指向数据尾
                *end;                    //指向缓存区尾
};

 

skb_shared_info:
 1 struct skb_shared_info {                  //保存数据块的附加信息
 2     atomic_t    dataref;                  //引用计数器
 3     unsigned short    nr_frags;
 4     unsigned short    gso_size;
 5     /* Warning: this field is not always filled in (UFO)! */
 6     unsigned short    gso_segs;
 7     unsigned short  gso_type;
 8     __be32          ip6_frag_id;
 9     struct sk_buff    *frag_list;
10     skb_frag_t    frags[MAX_SKB_FRAGS];
11 };

 

posted @ 2015-05-20 20:28  荆书凝  阅读(700)  评论(0编辑  收藏  举报