Linux内核-协议栈-主要函数调用栈

  1. 云栖社区>
  2. 博客>
  3. 正文

Linux内核-协议栈-主要函数调用栈

feilengcui008 2016-03-26 23:29:43 浏览914
展开阅读全文
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/feilengcui008/article/details/50989571

本文主要记录Linux协议栈相关的主要系统调用的一些主要的函数调用栈,备忘。目前添加socket/connect

1.sys_socket

  • bsd socket layer

    => sys_create net/socket.c

    => socket_create net/socket.c

    => __socket_create net/socket.c

    => sock_alloc net/socket.c

  • inet sock layer

    => net_families[family]->create net/socket.c

    => inet_create net/ipv4/af_inet.c

    => list_for_each_entry_rcu(answer, &inetsw[sock->type], list)

    => sock->ops = answer->ops //绑定每个协议族的proto_ops到socket结构上,proto_ops通常是与下层传输层的接口比如inet_connect,inet_*

    => sk_alloc(net, PF_INET, GFP_KERNEL, answer->prot) net/core/sock.c

    => sk_prot_alloc net/core/sock.c

    => kmem_cache_alloc(prot->slab) net/core/sock.c

    => sk->sk_prot = prot; sk->family = family net/core/sock.c

    => sock_init_data net/core/sock.c

    => skb_queue_head_init(&sk->sk_receive_queue) net/core/sock.c
    skb_queue_head_init(&sk->sk_write_queue)
    skb_queue_head_init(&sk->sk_error_queue)

    => sk->sk_state = TCP_CLOSE
    sk_set_socket(sk, sock)

    => sk->sk_prot->init(sk)

  • transport layer

    => tcp_v4_init_sock net/ipv4/tcp_ipv4.c

    => tcp_init_sock net/ipv4/tcp.c

    => icsk->icsk_af_ops = &ipv4_specific net/ipv4/tcp_ipv4.c //这里挂接传输层的读写处理,每个sock结构有一个inet_connection_sock的队列负责接收对端的socket


2.connect

  • bsd socket layer

    => sys_connect net/socket.c

    => sock->ops->connect(sock->proto_ops->connect) net/socket.c

  • inet sock layer

    => inet_stream_ops->connect net/ipv4/af_inet.c

    => inet_stream_connect net/ipv4/af_inet.c

    => __inet_stream_connect net/ipv4/af_inet.c

    => sock->sk->sk_prot->connect net/ipv4/af_inet.c

  • transport layer

    => tcp_prot->connect(tcp_v4_connect) net/ipv4/tcp_ipv4.c

    => ip_route_connect net/ipv4/tcp_ipv4.c

    => ip_route_connect_init include/net/route.h

    => flowi4_init_output include/net/flow.h

    => tcp_set_state(sk, TCP_SYN_SENT) net/ipv4/tcp_ipv4.c

    => tcp_connect net/ipv4/tcp_output.c

    => tcp_connect_init net/ipv4/tcp_output.c

    => sk_stream_alloc_skb net/ipv4/tcp.c

    => __alloc_skb net/core/skbuff.c

    => kmem_cache_alloc_node

    => tcp_connect_queue_skb net/ipv4/tcp_output.c

    => __tcp_add_write_queue_tail include/net/tcp.h

    => tcp_transmit_skb net/ipv4/tcp_output.c

    => icsk->icsk_af_ops->queue_xmit

  • ip layer

    => ip_queue_xmit net/ipv4/ip_output.c

    => ip_route_output_ports net/ipv4/ip_output.c 路由

    => ip_local_out include/net/ip.h

    => ip_local_out_sk net/ipv4/ip_output.c

    => __ip_local_out net/ipv4/ip_output.c netfilter检查

    => nf_hook (netfilter hooks) include/linux/netfilter.h

    => nf_hook_thresh include/linux/netfilter.h

    => nf_hook_slow include/linux/netfilter.h

    => nf_iterate net/netfilter/core.c

    => dst_output_sk include/net/dst.h

    => dst_entry->output include/net/dst.h

    => ip_output? net/ipv4/ip_output.c

    => ip_finish_output net/ipv4/ip_output.c

    => ip_fragment net/ipv4/ip_output.c

    => ip_finish_output2 net/ipv4/ip_output.c

  • hardware related layer

    => dst_neigh_output include/net/dst.h

    => neigh_hh_output include/net/neighbour.h

    => dev_queue_xmit net/core/dev.c

    => __dev_queue_xmit net/core/dev.c

    => netdev_pick_tx net/core/flow_dissector.c

    => __dev_xmit_skb net/core/dev.c

    => q->enqueue

    => __qdisc_run(q) net/sched/sch_generic.c

    => qdisc_restart net/sched/sch_generic.c

    => dequeue_skb net/sched/sch_generic.c

    => skb_get_tx_queue net/sched/sch_generic.c

    => netdev_get_tx_queue net/sched/sch_generic.c

    => sch_direct_xmit net/sched/sch_generic.c

    => validate_xmit_skb_list net/sched/sch_generic.c

    => dev_hard_start_xmit net/core/dev.c

    => xmit_one net/core/dev.c

    => netdev_start_xmit include/linux/netdevice.h

    => net_device_ops->ndo_start_xmit include/linux/netdevice.h

    => driver layer?

ref:
1. linux-3.19.3 src
2. Linux IP Networking A Guide to the Implementation and Modification of the Linux Protocol Stack

网友评论

登录后评论
0/500
评论
feilengcui008
+ 关注