合入代码:
这是运行日志:
https://gitee.com/r77683962/linux-6.9.0/raw/master/test_log/kern_tcp_ip.log
日志截取部分(也不知道对不对,凭感觉走。。。。)
从日志来看,这下边这个感觉接近真相了(图片版本)感觉有点像TCP调用IP层,IP层调用到L2层,不知道对不对,理解基本靠蒙:
非图片版本:
16:08:48.909399 PC kernel: net/ipv4/tcp.c tcp_recvmsg TCP: sk->sk_family: 2, sk->sk_portpair: 3394812673, sk->sk_dport: 47873, sk->sk_daddr: 2637854922, sk->sk_rcv_saddr: 1979754688
16:08:48.909659 PC kernel: include/net/l3mdev.h l3mdev_l3_rcv IPv4:
16:08:48.909666 PC kernel: net/ipv4/tcp_ipv4.c tcp_v4_rcv TCP:
16:08:48.909846 PC kernel: net/ipv4/tcp_ipv4.c tcp_v4_do_rcv TCP:
16:08:48.909851 PC kernel: include/net/l3mdev.h l3mdev_l3_rcv IPv4:
16:08:48.909859 PC kernel: net/ipv4/tcp_ipv4.c tcp_v4_rcv TCP:
16:08:48.909925 PC kernel: net/ipv4/tcp_ipv4.c tcp_v4_do_rcv TCP:
16:08:48.910600 PC kernel: net/ipv4/tcp_output.c tcp_send_delayed_ack TCP: sk->sk_family: 2, sk->sk_portpair: 3394812673, sk->sk_dport: 47873, sk->sk_daddr: 2637854922, sk->sk_rcv_saddr: 1979754688, sk->sk_state: 1
16:08:48.910617 PC kernel: net/ipv4/tcp.c tcp_recvmsg TCP: sk->sk_family: 2, sk->sk_portpair: 3394812673, sk->sk_dport: 47873, sk->sk_daddr: 2637854922, sk->sk_rcv_saddr: 1979754688
16:08:48.910629 PC kernel: message repeated 5 times: [ net/ipv4/tcp.c tcp_recvmsg TCP: sk->sk_family: 2, sk->sk_portpair: 3394812673, sk->sk_dport: 47873, sk->sk_daddr: 2637854922, sk->sk_rcv_saddr: 1979754688]
16:08:48.910630 PC kernel: net/ipv4/tcp.c tcp_sendmsg TCP: sk->sk_family: 2, sk->sk_portpair: 3394812673, sk->sk_dport: 47873, sk->sk_daddr: 2637854922, sk->sk_rcv_saddr: 1979754688
16:08:48.910636 PC kernel: net/ipv4/tcp.c tcp_push TCP:
16:08:48.910638 PC kernel: net/ipv4/tcp_output.c __tcp_push_pending_frames TCP:
16:08:48.910639 PC kernel: net/ipv4/tcp_output.c tcp_write_xmit TCP:
16:08:48.910641 PC kernel: net/ipv4/tcp_output.c tcp_transmit_skb TCP:
16:08:48.910643 PC kernel: net/ipv4/tcp_output.c __tcp_transmit_skb TCP:
16:08:48.910644 PC kernel: net/ipv4/tcp_output.c __tcp_transmit_skb TCP: sk->sk_family: 2, sk->sk_portpair: 3394812673, sk->sk_dport: 47873, sk->sk_daddr: 2637854922, sk->sk_rcv_saddr: 1979754688, sk->sk_state: 1
16:08:48.910646 PC kernel: net/ipv4/tcp_output.c tcp_event_ack_sent TCP: sk->sk_family: 2, sk->sk_portpair: 3394812673, sk->sk_dport: 47873, sk->sk_daddr: 2637854922, sk->sk_rcv_saddr: 1979754688, sk->sk_state: 1
16:08:48.910648 PC kernel: net/ipv4/tcp_output.c tcp_event_data_sent TCP: sk->sk_family: 2, sk->sk_portpair: 3394812673, sk->sk_dport: 47873, sk->sk_daddr: 2637854922, sk->sk_rcv_saddr: 1979754688, sk->sk_state: 1
16:08:48.910650 PC kernel: net/ipv4/ip_output.c ip_queue_xmit
16:08:48.910652 PC kernel: net/ipv4/ip_output.c __ip_queue_xmit
16:08:48.910654 PC kernel: net/ipv4/ip_output.c ip_local_out
16:08:48.910655 PC kernel: net/ipv4/ip_output.c __ip_local_out
16:08:48.910657 PC kernel: include/net/l3mdev.h l3mdev_ip_out
16:08:48.910658 PC kernel: include/net/l3mdev.h l3mdev_l3_out
kern.log完整版本:
登录 - Gitee.comhttps://gitee.com/r77683962/linux-6.9.0/raw/master/test_log/kern_tcp_ip_l2.log
打印日志代码合入:
由于这也是不断摸索的,不同电脑打印效果或者调用网络层次的函数可能不太一样。
现在发现日志量比较大,如果是自已学习摸索,可以根据实际情况把不需要打印的日志代码去掉。
有时我会上传在内核源代码中添加打印日志的代码,编译日志,查看内核运行日志三部分,为什么呢?
1、 内核源代码中添加打印日志的代码,这块一般是看代码,自已也思索,因为有的代码太复杂,看不懂(难道那些巨佬为了显摆自已的代码水平高吗,doge),有些打印信息也不一定对,有错误的地方等等;
2、编译日志,在修改代码的时候其实要小心,全量编译是比较耗时的,我这估计要编译7个小时,修改代码如果不小心修改到依赖层次偏底层的代码,那么所有直接依赖和间接依赖的源代码都需要重新编译,那么有什么办法可以找代码层级较高的源码(一个非常简单粗暴的办法:在全量编译里边找越往后的代码级别越高)呢?
比如:我的全量编译日志是这个:
https://gitee.com/r77683962/linux-6.9.0/raw/master/compile_log/compile.log
3、查看内核运行日志,这部分主要是可以看到添加到内核源代码的打印日志,有一点点成就感,doge ,而且可以根据自已实验学习的需要打印对自已有用的信息,便天学习,定位问题什么的。。。