轉:Linux-2.6.21.1 網絡函數調用流程
http://www.cublog.cn/u/12313/showart_312426.html
msn: [email protected]
來源:http://yfydz.cublog.cn
接收以太幀:
netif_rx
-> queue //管理隊列
-> netif_receive_skb // 將幀的拷貝交給註冊的協議函數處理、初始化skb->{h,nh,mac}
-> bond //多個接口綁定成一個
-> packet_type_all: deliver_skb
-> bridge //橋接
接收IPv4包:
-> NF_HOOK(PREROUTING) //netfilter鉤子
->ip_rcv_finish //檢查包的地址、校驗和等
-> ip_route_input //路由緩存查找
-> ip_route_input_cached
-> ip_route_input_slow //路由表項查找
-> ip_mkroute_input
-> __mkroute_input
dst->input = ip_forward //數據包轉發處理
dst->output = ip_output //dst->output是包發送的處理
-> dst_input //如果skb->dst有效
-> LOCAL_IN: dst->input == ip_local_deliver //本地處理
-> NF_HOOK(NF_INPUT)
-> ip_local_deliver_finish //處理分片等
-> ipprot->handler(tcp, udp, icmp ...)
轉發:
ip_forward
-> xfrm4_route_forward (net/xfrm.h, get xfrm_dst) //IPSec策略檢驗
-> xfrm_route_forward
-> __xfrm_route_forward
-> xfrm_lookup
-> xfrm_find_bundle
-> afinfo->find_bundle == __xfrm4_find_bundle
-> xfrm_bundle_create
-> afinfo->bundle_create == __xfrm4_bundle_create
tunnel mode //隧道模式
-> xfrm_dst_lookup
-> afinfo->dst_lookup == xfrm4_dst_lookup
-> __ip_route_output_key
-> dst_list: dst->list=policy_bundles, policy->bundles = dst
-> NF_HOOK(NF_FORWARD) //netfilter鉤子
-> ip_forward_finish
-> dst_output
icmp_send
-> ip_route_output_key //查找目的地址的路由
-> ip_route_output_flow
-> icmp_push_reply
-> ip_append_data
-> skb_queue_walk
-> ip_push_appending_frames
tcp:
tcp_connect // tcp連接
-> ip_route_connect
-> ip_route_output_flow
tcp_sendmsg // tcp發送載荷數據
-> __tcp_push_appending_frames
-> tcp_write_xmit
-> tcp_transmit_skb
-> net_xmit_eval
-> icsk->icsk_af_ops->queue_xmit == ipv4_specific->queue_xmit == ip_queue_xmit
-> tcp_push_one
-> tcp_transmit_skb
-> net_xmit_eval
-> icsk->icsk_af_ops->queue_xmit == ipv4_specific->queue_xmit == ip_queue_xmit
//不知所云,前面是接收TCP的處理,到了後面又轉成發送了??????????????
-> __inet_lookup
-> xfrm_policy_check
-> tcp_v4_do_rcv
-> tcp_rcv_state_process
-> icsk->icsk_af_ops->conn_request == tcp_v4_conn_request
-> tcp_v4_send_synack
-> ip_build_and_send_pkt
-> NF_HOOK( NF_OUTPUT ) //??????????????????????
udp:
udp_sendmsg
-> ip_route_output_flow
-> ip_append_data
-> __skb_queue_tail( sk_write_queue )
-> udp_push_pending_frames
-> ip_push_pending_frames
raw_sendmsg
-> ip_route_output_flow
-> ip_append_data
-> __skb_queue_tail( sk_write_queue )
-> ip_push_pending_frames
ip_push_pending_frames
-> __skb_dequeue(sk_write_queue)
-> NF_HOOK(NF_OUTPUT)
-> dst_output
ip_queue_xmit
-> ip_route_output_flow
-> xfrm_lookup
-> xfrm_find_bundle
-> bundle_create
-> afinfo->bundle_create == __xfrm4_bundle_create
-> xfrm_dst_lookup
-> afinfo->dst_lookup == xfrm4_dst_lookup
-> __ip_route_output_key
-> dst_list
-> dst->list=policy_bundles, policy->bundles = dst
-> dst_output
-> dst->output
-> dst->output == xfrm_dst->output == xfrm4_output == xfrm4_state_afinfo->output
-> NF_HOOK(POSTROUTING)
-> xfrm4_output_finish
-> gso ?
-> xfrm4_output_finish2
-> xfrm4_output_one
-> mode->output
-> type->output
-> skb->dst=dst_pop(skb->dst)
-> nf_hook(NF_OUTPUT)
-> !dst->xfrm
-> dst_output
-> nf_hook(POSTROUTING)
-> dst->output == ip_output
-> NF_HOOK(POSTROUTING)
-> ip_finish_output
-> ip_finish_output2
-> hh_output == dev_queue_xmit