Linux 内核网络协议栈 ------sk_buff 结构体 以及 完全解释

Linux 内核网络协议栈 ------sk_buff 结构体 以及 完全解释 (2.6.16)

在2.6.24之后这个结构体有了较大的变化,此处先说一说2.6.16版本的sk_buff,以及解释一些问题。

一、

先直观的看一下这个结构体~~~~~~~~~~~~在下面解释每个字段的意义~

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;

     /*
      * 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;
     __u32                   priority;
     __u8                    local_df:1,
                             cloned:1,
                             ip_summed:2,
                             nohdr:1,
                             nfctinfo:3;
     __u8                    pkt_type:3,
                             fclone:2,
                             ipvs_property:1;
     __be16                  protocol;

     void                    (*destructor)(struct sk_buff *skb);

#ifdef CONFIG_NETFILTER
__u32 nfmark;
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

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

};

: next和prev,这两个域是用来连接相关的skb的(例如如果有分片,将这些分片连接在一起可以)

: sk,指向报文所属的套接字指针

: tstamp,记录接收或者传输报文的时间戳

: dev和input_dev,记录接收或者发送的设备

: union u,对于一个层次,例如tcp层,可能有很多不同的协议,他们的协议头不一样,那么这个联合体就是记录这些协议头的。

 此处u就是代表传输层

: union nh,代表网络层头

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值