Linux网络设备驱动-- skb
代码基于Linux kernel 3.13.0
传说中的skb, 其数据结构是struct sk_buff (include/linux/skbuff.h)。 这里捡个人认为重要的讲讲:
struct sk_buff {
/* These two members must be first. */
struct sk_buff*next;
struct sk_buff*prev;
ktime_ttstamp;
struct sock*sk;
struct net_device*dev; //对应的net_device
/*
* 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.
*/
charcb[48] __aligned(8); //cb, 驱动经常用它来保存一些private结构
unsigned long_skb_refdst;
#ifdef CONFIG_XFRM
structsec_path*sp;
#endif
unsigned intlen, //skb size或skb head size(data_len!=0)
data_len; //data_len!=0说明有分片
__u16mac_len,
hdr_len;
union {
__wsumcsum;
struct {
__u16csum_start;
__u16csum_offset;
};
};
__u32priority; //优先级
kmemcheck_bitfield_begin(flags1);
__u8local_df:1,
cloned:1,
ip_summed:2,
nohdr:1,
nfctinfo:3;
__u8pkt_type:3,
fclone:2,
ipvs_property:1,
peeked:1,
nf_trace:1;
kmemcheck_bitfield_end(flags1);
__be16protocol;