免费注册 查看新帖 |

Chinaunix

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

LINUX协议栈之(5) : IP layer process flow [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-12-24 11:57 |只看该作者 |倒序浏览
Layer 3 : IP Protocol handling
Now we come into the IP world!
1.
The main ip receive routine is : ip_rcv();
2. The process flow of ip_rcv() function
2.1 first checking if this SKB is for other host, if so, free this SKB and return NET_RX_DROP directly
2.2 The share checking
    Checking if more than one person has a reference to this SKB buffer.
    The function skb_share_check() performs this
checking work. If the SKB is shared, then this skb will be cloned and
the old copy drops a reference, the new clone with a single reference
is returned. If the buffer is not shared, the original buffer is
returned.
    !!! i have a question here in the function
skb_share_check() : if the skb->users != 1 then we will clone this
skb and then call kfree_skb() function. In this function, we'll
continue to check the skb->users's value, if this value is 1 then
directly call __kfree_skb() to free this skb, else if this value != 1
then we'll first drop its reference and then test if this value is
equal to 0, if this value != 0 then call __kfree_skb(), else return
directly. ??? So, either skb->user equal to 1 or 2(3,4...), it will
always call __kfree_skb() ???
2.3 IP Layer header checking work
    pskb_may_pull() function check the IP header's length validation.
    first check the ip header length, atleast 5.
    the version must be 4
    the ip package size, at least the size of an ip header.   
    Check the CSUM of this IP header
    Check the total length of this IP package
    Then call the function : pskb_trim_rcsum(). this
function trim the received skb and update the checksum. Because the
transport layer may padded the buffer before.
2.4 The last step : Netfilter or Input finishe ?
    At the last step, we are caught with one of the most
interesting things in linux kernel : netfilter. It just a very famous
macro : NF_HOOK!
    While we'll not plan to describe the netfilter here, so we just jump into our function : ip_rcv_finish().
2.5 Complete the IP receive work : ip_rcv_finish()
    This function is not as simple as it looks!
    First we'll initialise the virtual path cache for
this skb and it describes how the skb travels inside the linux. The
function we used is ip_route_input().
    Second we'll check if this IP packet has options
header, if so we'll handle the option header by calling
ip_rcv_options() function.
    At last, we call the dst_input() to finish this process flow.
3. Enough for outlines
    Now we describes the simple process flow of IP layer
in linux kernel, and next we'll learn how the skb travels inside the
linux kernel stack --- the route!s
               
               
               

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

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP