首先看一下网络驱动必用结构体struct sk_buff
不怎么使用的就没有出现解释:
struct sk_buff {
/* These two members must be first. */
struct sk_buff *next;
struct sk_buff *prev;
struct sock *sk; //哪个socket套机字拥有此buffer
ktime_t tstamp; //到达所使用的时间
struct net_device *dev;
unsigned long _skb_dst; //目的入口
#ifdef CONFIG_XFRM
struct sec_path *sp;
#endif
/*
* 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; //数据长度
__u16 mac_len, //链路层头部长度
hdr_len; //skb_clone的skb可改写头部的长度
//校验
union {
__wsum csum;
struct {
__u16 csum_start;
__u16 csum_offset;
};
};
__u32 priority; //包的优先级
kmemcheck_bitfield_begin(flags1);
__u8 local_df:1, //是否允许分片
cloned:1, //头部被复制到子分片
ip_summed:2, //ip校验和
nohdr:1, //有效载荷的参考
nfctinfo:3;
__u8 pkt_type:3, //包的类型
fclone:2, //skbuff clone状态
ipvs_property:1, //ipvs拥有
peeked:1, //此包已发送过
nf_trace:1; //网络过滤包的追踪标志
__be16 protocol:16; //协议版本
kmemcheck_bitfield_end(flags1);
void (*destructor)(struct sk_buff *skb); //自动释放
#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
struct nf_conntrack *nfct;
struct sk_buff *nfct_reasm;
#endif
#ifdef CONFIG_BRIDGE_NETFILTER
struct nf_bridge_info *nf_bridge;
#endif
int iif;
#ifdef CONFIG_NET_SCHED
__u16 tc_index; /* traffic control index */
#ifdef CONFIG_NET_CLS_ACT
__u16 tc_verd; /* traffic control verdict */
#endif
#endif
kmemcheck_bitfield_begin(flags2);
__u16 queue_mapping:16;
#ifdef CONFIG_IPV6_NDISC_NODETYPE
__u8 ndisc_nodetype:2;
#endif
kmemcheck_bitfield_end(flags2);
/* 0/14 bit hole */
#ifdef CONFIG_NET_DMA
dma_cookie_t dma_cookie;
#endif
#ifdef CONFIG_NETWORK_SECMARK
__u32 secmark;
#endif
__u32 mark;
__u16 vlan_tci;
sk_buff_data_t transport_header; //如tcp/udp头部
sk_buff_data_t network_header; //ip头部
sk_buff_data_t mac_header; //数据链路层头部 mac头部
/* These elements must be at the end, see alloc_skb() for details. */
sk_buff_data_t tail; //有效数据指针尾部
sk_buff_data_t end; //缓冲区结束处