免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 720 | 回复: 0
打印 上一主题 下一主题

The skb length when allocation [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-07-19 16:40 |只看该作者 |倒序浏览
The skb length when allocation
==============================
1. When L2 receive a packet
When L2 receive a packet, the packet is a L3 packet. Assume the packet length is pkt_len.
L2 allocate a skb with length pkt_len+16. The addition 16 bytes is reserved for L2 header(MAC address).
The pkt_len bytes contains L3 header and L3 content.
Since pkt_len contains all the L3(header and content), if we do tunnel, we need not modify the
receive process of L2.
2. When L4 send a packet
When a user space program call the send() system call to send a buffer with the length of buf_len,
assume the protocol is TCP, then the Linux kernel will allocate a skb with the length of:
buf_len + MAX_TCP_HEADER
The following is the definition of TCP_HEADER_LEN:
/*
*    Compute the worst case header length according to the protocols
*    used.
*/

#if !defined(CONFIG_AX25) && !defined(CONFIG_AX25_MODULE) && !defined(CONFIG_TR)
#define LL_MAX_HEADER    32
#else
#if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
#define LL_MAX_HEADER    96
#else
#define LL_MAX_HEADER    48
#endif
#endif
#if !defined(CONFIG_NET_IPIP) && \
    !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE)
#define MAX_HEADER LL_MAX_HEADER
#else
#define MAX_HEADER (LL_MAX_HEADER + 48)
#endif
#define MAX_TCP_HEADER    (128 + MAX_HEADER)
From the above code, we can conclude:
MAX_TCP_HEADER = 128 + LL_HEADER + (48 if support IPv6 or IP tunnel)
LL_HEADER(L3 Header) = 96(AX25)|48(TR)|32
If the kernel do not support IPv6,AX25 and TR, then MAX_TCP_HEADER = 128+LL_MAX_HEADER = 128+32
128 bytes only contain TCP header
32 bytes only contain L3 header
If the kernel support IP tunnel, there will be 48 bytes more.
If the kernel support AX25, the L3 header will be 96 instead of 32
If the kernel support TR, the L3 header will be 48
If we do tunnel, we can modify the above macros, that's easy :-)
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/1938/showart_142730.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP