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
阅读(1561) | 评论(0) | 转发(0) |