標籤:
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 };
Linux skbuff注釋筆記