注册 | 登录 忘记密码? 51cto首页 | 博客 | 论坛 | 招聘
热点文章 Cisco IOS下载
 帮助

sk_buff结构


2008-03-21 16:34:31
 标签:网络 linux sk_buff   [推送到技术圈]

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://cutebunny.blog.51cto.com/301216/67253
最近翻阅了一些linux网络协议方面的资料,发现在sk_buff的相关结构上有些细节上的不一致。于是,埋头啃代码,整理相关细节如下。(内核版本2.6.22)
根据sk_buff结构和__alloc_skb(),sk_buff结构及数据内存区初始状态为:
__alloc_skb()的功能和参数为
/**
 * __alloc_skb - allocate a network buffer
 * @size: size to allocate
 * @gfp_mask: allocation mask
 * @fclone: allocate from fclone cache instead of head cache
 *  and allocate a cloned (child) skb
 * @node: numa node to allocate memory on
 *
 * Allocate a new &sk_buff. The returned buffer has no headroom and a
 * tail room of size bytes. The object has a reference count of one.
 * The return is the buffer. On a failure the return is %NULL.
 *
 * Buffers may only be allocated from interrupts using a @gfp_mask of
 * %GFP_ATOMIC.
 */
struct sk_buff *__alloc_skb(unsigned int size, gfp_t gfp_mask, int fclone, int node)
其中,图中size并不完全等于参数传入的size,在函数中经过对齐
size = SKB_DATA_ALIGN(size);
另外,skb->len在经过memset(skb, 0, offsetof(struct sk_buff, tail));后已巧妙地设置为0.
skb->truesize = size + sizeof(struct sk_buff);可见,truesize为sk_buff结构本身大小与数据区长度size之和,不包括skb_shared_info.
data = kmalloc_node_track_caller(size + sizeof(struct skb_shared_info), gfp_mask, node);此句亦可证明。

本文出自 “bunny的技术之旅” 博客,请务必保留此出处http://cutebunny.blog.51cto.com/301216/67253





    文章评论
 
2008-03-21 16:40:32
来看看。。

 

发表评论

昵   称:
验证码:  点击图片可刷新验证码  博客过2级,无需填写验证码
内   容: