分类: LINUX
2011-11-22 11:36:26
/**
* dev_alloc_skb - allocate an skbuff for receiving
* @length: length to allocate
*
* Allocate a new &sk_buff and assign it a usage count of one. The
* buffer has unspecified headroom built in. Users should allocate
* the headroom they think they need without accounting for the
* built in space. The built in space is used for optimisations.
*
* %NULL is returned if there is no free memory. Although this function
* allocates memory it can be called from an interrupt.
*/
static inline struct sk_buff *dev_alloc_skb(unsigned int length)
{
return __dev_alloc_skb(length, GFP_ATOMIC);
}
首先L2的地址一共是14(6+6+2)个BYTE,而MAC+IP+TCP/UDP结构为:L2+L3(IP addr)+L4。
按照常理L2地址是在L3后加, 所以在ALLOCSKB的时候要留14个BYTE,为了以后给L2用.但是计算机一般是4字节对齐的, 如果留14个BYTE那么IP只能排在15个byte位子, ip头要经常访问所以这样效率似乎不好.于是在预留2个(14+2 = 16) 正好让IP头4字节对齐.
/**
* skb_reserve - adjust headroom
* @skb: buffer to alter
* @len: bytes to move
*
* Increase the headroom of an empty &sk_buff by reducing the tail
* room. This is only allowed for an empty buffer.
*/
static inline void skb_reserve(struct sk_buff *skb, int len)
{
skb->data += len;
skb->tail += len;
}
skb_reserve(skb,2);
The networking layer currently aligns IP headers in rx packets. It does this via skb_reserve(,2).skb_put 于 skb_push: