140 likes | 301 Views
Network Applications. user. kernel. socket. BSD Sockets. sock. INET Sockets. sk_buff. TCP. UDP. IP. ARP. PPP. SLIP. Ethernet. sys_socketcall(). send. ip_queue_xmit. sys_send(). sock->ops->sendmsg. dev_queue_xmit. inet_sendmsg(). do_dev_queue_xmit. sk->prot->sendmsg.
E N D
Network Applications user kernel socket BSD Sockets sock INET Sockets sk_buff TCP UDP IP ARP PPP SLIP Ethernet
sys_socketcall() send ip_queue_xmit sys_send() sock->ops->sendmsg dev_queue_xmit inet_sendmsg() do_dev_queue_xmit sk->prot->sendmsg tcp_sendmsg() dev->hard_start_xmit el3_start_xmit() do_tcp_sendmsg() tcp_send_skb sk->prot->queue_xmit
do_tcp_sendmsg() • Allocate sk_buff • construct hardware and IP header • sk->prot->build_header() • ip_build_header • construct TCP header
ip_queue_xmit() • Partially initialize skb (sk_buff) • check “free” value • free == 1: don’t free, keep skb on the sk send list • free == 0: after device send out, it will be freed • compute checksum • if lookback: call ip_lookback() • if fragmentation: call if_fragment() • call dev_queue_xmit()
do_dev_queue_xmit() • Lock device • check if transmission • find the corresponding list • queue the skb in the tail of list • dequeue the first skb in the list and call the dev->hard_start_xmit()
el3_interrupt() tcp_rcv el3_rx() tcp_data() netif_rx() tcp_queue() sk->data_ready() net_bh() def_callback2() pt_prev->fun() ip_rcv() ipprot->handler()
Function Illustration • el3_interrupt() • get the device interface • call el3_rx() • el3_rx() • allocate sk_buff • determine the packet’s protocol ID • call netif_rx()
Function Illustration (Cont.) • netif_rx() • check if backlog_size is appropriate • if no => drop • else enqueue in the system backlog list • call mark_bh()
Function Illustration (Cont.) • net_bh() • dev_transmit(): check each network interface if anyone is ready to transmit • _sbk_unlink(): dequeue the sk_buff from the backlog list • search the two system list for packet type • ptype_all: ETH_P_ALL • ptype_base[]: main protocol list • call pt_prev->func() : i.e. ip_rcv()
Function Illustration (Cont.) • ip_rcv() • correction checking • ip_options_compile: ip options preprocessing • ip_defrag() • if my packet • ip_option_processing • check if raw ip • find the protocol and call ipprot->handler(): tcp_rcv() • else ip_forward()
Function Illustration (Cont.) • tcp_rcv() • _tcp_v4_lookup(): find the upper INET sock structure • call tcp_data() • tcp_data() • handle the data • call tcp_queue
Function Illustration (Cont.) • tcp_queue() • tcp_insert_skb(): add a sk_buff to the tcp receive queue (sk->receive_queue) • sk->data_ready(): def_callback2() • def_callback2() • wake up the sleeping process
sys_socketcall() sys_recv() inet_recvmsg() tcp_recvmsg()