JustKernel

Ray Of Hope

Kernel Protocol Stack

  • IP Processing: The IP protocol receive function ip_recv() is called when an IP packet is dequeued. It verifies packet integrity and invokes any netfilter hooks, then calls ip_rcv_finish(), which routes the packet over the network or delivers it locally by ip_local_deliver(). There, the highter layer protocol is determined and the corresponding handler function is invoked.: tcp_v4_rcv() and udp_rcv() are two examples
  • TCP Processing: After header sanity checks, the TCP code looks up the socket associeated with the packet. Each socket has a lock to protect its data from an un-synchronised modification. The packet must be processed immediately by a call to tcp_v4_do_rcv(), which is also called to drain the backlog queue.It is through this function that packets are acknowledged , and window and round-trip time estimates are update.  The packet is handled on the so-called fast path if its exactly the next packet expected in a received sequence with no gaps. If, in addition, the socket belongs to the currently active process and the data fits into the application-supplied buffer, the data will be copied directly from the sk_buff to user memory. This derect copy can also occur on the slow path if the packet fills the beginning of the first hole in the received stream.On either path, if the data cannot be copied directly to user space, it goes onto the receive queue. Packets in the receive queue  are guaranteed in order, acked and without gaps. Packets in the out-of-sequence queue are moved to the receive queue when additional packets fill the preceding holes in the data stream.
  • UDP Processing: When a UDP packet arrives from the IP layer through ip_local_deliver(), it is passed on to udp_rcv(). udp_rcv()’s mission is to verify the integrity of the UDP packet and to queue(udp_queue_rcv_skb()) one of more copies for deliver to multicast and broadcast sockets and exactly one copy tounicast sockets.
  • Data Receivng Process: Packet data is finally copied from the socket’s receive buffer to user space by  data receiving process through socket-related receive system calls. The receivning process supplies a memory address and number of bytes to be transferred, either in a struct iovec , or as two parameters gathered in to such a struct by kernel. All the TCP socket related receive system calls result in the final calling of tcp_recvmsg(), which will copy packet data from socket’s buffers (receive queue, prequeue, backlog queue) through iovec. For UDP, all the socket-related receivng system calls result in the final calling of udp_recvmsg() , which is th efront end to the UDP transport receive mechanism.When udp_recvmsg() is called, data inside receive queue is copied through iovec to user space directly.

Originally Posted On: 2010-07-20 04:19:34

Anshul Makkar, anshul_makkar@justkernel.com

Tags:


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.