- 论坛徽章:
- 0
|
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 |
|