【linux】内核从tcp层调用IP层摸索中

合入代码:

登录 - Gitee.comhttps://gitee.com/r77683962/linux-6.9.0/commit/f5a93955e16d148a70f98e0f300f455b3ab594f3

这是运行日志:

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

打印日志代码合入:

登录 - Gitee.comhttps://gitee.com/r77683962/linux-6.9.0/commit/aaa5103ae41d662594c97f7aa90e4c07e25795e8

登录 - Gitee.comhttps://gitee.com/r77683962/linux-6.9.0/commit/f5a93955e16d148a70f98e0f300f455b3ab594f3

由于这也是不断摸索的,不同电脑打印效果或者调用网络层次的函数可能不太一样。

现在发现日志量比较大,如果是自已学习摸索,可以根据实际情况把不需要打印的日志代码去掉。

有时我会上传在内核源代码中添加打印日志的代码,编译日志,查看内核运行日志三部分,为什么呢?

1、 内核源代码中添加打印日志的代码,这块一般是看代码,自已也思索,因为有的代码太复杂,看不懂(难道那些巨佬为了显摆自已的代码水平高吗,doge),有些打印信息也不一定对,有错误的地方等等;

2、编译日志,在修改代码的时候其实要小心,全量编译是比较耗时的,我这估计要编译7个小时,修改代码如果不小心修改到依赖层次偏底层的代码,那么所有直接依赖和间接依赖的源代码都需要重新编译,那么有什么办法可以找代码层级较高的源码(一个非常简单粗暴的办法:在全量编译里边找越往后的代码级别越高)呢?

比如:我的全量编译日志是这个:

https://gitee.com/r77683962/linux-6.9.0/raw/master/compile_log/compile.log

3、查看内核运行日志,这部分主要是可以看到添加到内核源代码的打印日志,有一点点成就感,doge ,而且可以根据自已实验学习的需要打印对自已有用的信息,便天学习,定位问题什么的。。。

相关推荐
小小代码狗1 小时前
SQLi-Labs 基础注入实战教程(Less-1 ~ Less-5and Less-9)
服务器·python·php
慕伏白1 小时前
【慕伏白】Linux 系统如何根据端口号关闭进程
linux·运维·服务器
letisgo51 小时前
VMware Workstation + Ubuntu 26.04 LTS 小白运维部署手册
linux·运维·ubuntu
蓝创工坊Blue Foundry1 小时前
图片文字提取到 Excel:批量任务如何先定义要交付的字段
运维·服务器·开发语言·数据库·自动化·ocr·excel
IT探索1 小时前
Linux 查找文件指令总结
linux·算法
晚风吹长发1 小时前
Docker使用——Docker容器及相关命令
linux·运维·服务器·docker·容器·架构
ShiXZ2131 小时前
Docker Compose 安装与配置指南
运维·docker·容器
sulikey2 小时前
个人Linux操作系统学习笔记11 - 环境变量
linux·笔记·学习
Kina_C2 小时前
NFS与Autofs快速讲解-从原理到实战配置
linux·nfs·autofs
麦聪聊数据2 小时前
企业数据市场建设(四):流程闭环与价值运营,让数据市场真正转起来
运维·数据库