skb学习整理

发表于:2007-07-04来源:作者:点击数: 标签:
想了解一些 linux 网络 实现机制,怎么办呢? --从skb开始吧。 所以新开一帖把以后的学习笔记就记录在这里。 如果所说有误,还请各位有为青年帮忙提醒一下,使俺能及时迷途知返^_^. 先贴几个相关数据结构: ---------------------- /
想了解一些linux网络实现机制,怎么办呢?
--从skb开始吧。
所以新开一帖把以后的学习笔记就记录在这里。
如果所说有误,还请各位有为青年帮忙提醒一下,使俺能及时迷途知返^_^.

先贴几个相关数据结构:

----------------------

/**
 *    struct sk_buff - socket buffer
 *    @next: Next buffer in list
 *    @prev: Previous buffer in list
 *    @list: List we are on
 *    @sk: Socket we are owned by
 *    @stamp: Time we arrived
 *    @dev: Device we arrived on/are leaving by
 *      @real_dev: The real device we are using
 *    @h: Transport layer header
 *    @nh: Network layer header
 *    @mac: Link layer header
 *    @dst: FIXME: Describe this field
 *    @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
 *    @__unused: Dead field, may be reused
 *    @cloned: Head may be cloned (check refcnt to be sure)
 *    @pkt_type: Packet class
 *    @ip_summed: Driver fed us an IP checksum
 *    @priority: Packet queueing priority
 *    @users: User count - see .c
 *    @protocol: Packet protocol from driver
 *    @security: Security level of packet
 *    @truesize: Buffer size
 *    @head: Head of buffer
 *    @data: Data head pointer
 *    @tail: Tail pointer
 *    @end: End pointer
 *    @destructor: Destruct function
 *    @nfmark: Can be used for communication between hooks
 *    @nfcache: Cache info
 *    @nfct: Associated connection, if any
 *    @nf_debug: Netfilter debugging
 *    @nf_bridge: Saved data about a bridged frame - see br.netfilter.c
 *      @private: Data which is private to the HIPPI implementation
 *    @tc_index: Traffic control index
 */

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

    struct sk_buff_head    *list;
    struct sock        *sk;
    struct timeval        stamp;
    struct net_device    *dev;
    struct net_device    *real_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 {
          struct ethhdr    *ethernet;
          unsigned char     *raw;
    } mac;

    struct  dst_entry    *dst;
    struct    sec_path    *sp;

    /*
     * 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,
                mac_len,
                csum;
    unsigned char        local_df,
                cloned,
                pkt_type,
                ip_summed;
    __u32            priority;
    unsigned short        protocol,
                security;

    void            (*destructor)(struct sk_buff *skb);
#ifdef CONFIG_NETFILTER
        unsigned long        nfmark;
    __u32            nfcache;
    struct nf_ct_info    *nfct;
#ifdef CONFIG_NETFILTER_DEBUG
        unsigned int        nf_debug;
#endif
#ifdef CONFIG_BRIDGE_NETFILTER
    struct nf_bridge_info    *nf_bridge;
#endif
#endif /* CONFIG_NETFILTER */
#if defined(CONFIG_HIPPI)
    union {
        __u32        ifield;
    } private;
#endif
#ifdef CONFIG_NET_SCHED
       __u32            tc_index;               /* traffic control index */
#endif

    /* These elements must be at the end, see alloc_skb() for details.  */
    unsigned int        truesize;
    atomic_t        users;
    unsigned char        *head,
                *data,
                *tail,
                *end;
};

---------------------

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

    __u32        qlen;
    spinlock_t    lock;
};

---------------------

本来有个很重要的的net_device 但是太大了,我就不放到这里了。好,先发这么多,把数据结构熟悉一下。

原文转自:http://www.ltesting.net