- 博客(53)
- 收藏
- 关注
原创 Generic XDP Hook
上一篇文章讲过bpf_prog_run_xdp是XDP 程序的最终调用函数,想要跟踪Generic XDP的代码可以从该函数入手。很显然你不应该从driver/,而是已改在net/目录下检索。jensonqiu@Bing$ grep -rn "bpf_prog_run_xdp" netnet/core/dev.c:4349: act = bpf_prog_run_xdp(xdp_prog, xdp);稍微过滤一下真相就呼之欲出了,函数的调用关系如下:bpf_prog_run_xdpnet
2022-02-23 15:29:32
727
原创 Native xdp hook 点
看到xdp功能的时候,你可能已经猜到了xdp一定有在内核中有hook,你也可能猜到了xdp的hook应该在程序中,但是你可能不知道xdp hook 具体在网卡驱动的那个流程中,今天走读了一遍xdp的代码逻辑,简单记录内容如下。bpf_prog_run_xdpbpf_prog_run_xdp函数是xdp的框架函数,你注册的xdp程序将会在这个函数中别逐一调用。xdp的hook是在内核驱动中 ? 你可以过滤一下这个函数,大概应该和我的差不多:jensonqiu@Bing$ grep
2022-02-22 18:15:38
1934
原创 BPF_PROG_TYPE_SOCKET_FILTER 功能实现
BPF_PROG_TYPE_SOCKET_FILTER,从宏字面意思比较容易想到实现的是socket filter功能,它区别于sockops和tracepoint等功能,需要额外借助setsockopt能力将功能函数和socket绑定,功能才能真正生效。如何定该类型在内核态功能函数中定义SEC("socketxxxx"),则会被解析为BPF_PROG_TYPE_SOCKET_FILTER类型功能。比如内核中实现的三个example程序:samples/bpf/sockex1_kern.c -
2022-02-20 14:07:02
2018
原创 ebpf tracepoint 功能分析
1. 查看系统支持的所有tracepointfind /sys/kernel/debug/tracing/events -type d可以查看到当前系统支持的所有tracepoint函数点,大家在利用tracepoint功能的时候最好先看看对应的子系统在那些地方有hook点,评估是否能满足功能。比如说你想内视TCP协议栈,那么你可以先tcp trace 支持那些功能:[root@xxx tcp]# ls /sys/kernel/debug/tracing/events/tcpenable t..
2022-02-19 22:08:02
1738
原创 ebpf xdp 挂载点分析
1. 查看支持xdp功能的网卡drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c:218: case XDP_SETUP_PROG:drivers/net/ethernet/cavium/thunder/nicvf_main.c:1848: case XDP_SETUP_PROG:drivers/net/ethernet/intel/i40e/i40e_main.c:11845: case XDP_SETUP_PROG:drivers/net/ethern
2022-02-19 22:00:41
1399
原创 ebpf sockops 代码解读
2032 static inline int tcp_call_bpf(struct sock *sk, int op, u32 nargs, u32 *args)2033 {2034 struct bpf_sock_ops_kern sock_ops;2035 int ret;20362037 memset(&sock_ops, 0, offsetof(struct bpf_sock_ops_kern, temp));2038 .
2022-02-19 18:08:54
1746
原创 ebpf sockops 功能分析
ebpf sockops 实现原理大家肯定好奇为什么通过ebpf sockops可以提取我们想要的数据 ?正常来说实现方式有两种,第一种是关键路径上埋钩子函数;第二种是kprobe的粘贴插入。 ebpf sockops 是通过第一种实现的,在关键路径上埋钩子函数了,所以想要扩展功能难哦,一般在内核版本升级时可以提前规划埋好钩子函数。ebpf sockops 支持那些功能ebpf sockops支持那些功能(关键看在什么路径上埋了钩子函数),看 下面代码吧...
2022-02-18 11:34:39
1909
3
原创 BBR 每秒带宽换算逻辑
/* Scale factor for rate in pkt/uSec unit to avoid truncation in bandwidth* estimation. The rate unit ~= (1500 bytes / 1 usec / 2^24) ~= 715 bps.* This handles bandwidths from 0.06pps (715bps) to 256Mpps (3Tbps) in a u32.* Since the minimum window i...
2022-01-19 15:04:59
369
原创 BBR拥塞控制状态机分析
目录BBR 源码文件的描述四个阶段理想状态图STARTUP进入和退出条件DRAIN进入和退出条件PROBE_BW进入和退出条件PROBE_RTT进入和退出条件PROBE_BW内部状态分析PROBE_UP状态进入和退出PROBE_DOWN状态进入和退出PROBE_USE状态进入和退出后续BBR 源码文件的描述* A BBR flow starts in STARTUP, and ramps up its sending rate quic..
2022-01-19 11:47:55
3139
原创 SYSCALL_DEFINE5 setsockopt 代码流程
SYSCALL_DEFINE5(setsockopt, int, fd, int, level, int, optname, char __user *, optval, int, optlen){ int err, fput_needed; struct socket *sock; if (optlen < 0) return -...
2018-12-14 14:47:41
698
原创 tso硬件分片是头部拷贝问题
//skb->date指向了二层头部地址,下面是计算 以太网头 + IP头 大小static inline int skb_transport_offset(const struct sk_buff *skb){ return skb_transport_header(skb) - skb->data;}static int e1000_tso(struct e1000_adapter...
2018-06-28 16:40:20
951
转载 Linux Kernel: Deadlocks and how to avoid them
Linux Kernel: Deadlocks and how to avoid themDeadlock Problem:Scenario 1: Self deadlock - "re-acquire lock"Say there's a thread A, it acquires lock X1 and then before relenquishing the lock, it re-acq...
2018-05-21 16:08:55
710
原创 RFC 793 为什么要发送reset,什么情况下发送reset
A variety of other cases are possible, all of which are accounted for by the following rules for RST generation and processing. Reset Generation As a general rule, reset (RST) must be sent w...
2018-05-19 11:02:45
513
原创 什么时候去发送 update windos报文
/* Clean up the receive buffer for full frames taken by the user, * then send an ACK if necessary. COPIED is the number of bytes * tcp_recvmsg has given to the user so far, it speeds up the * calcula...
2018-05-18 22:35:01
506
原创 Tcpdump抓包内核代码分析
注册pf_packet协议 .create函数是在PF_PACKET类型socket创建时调用,调用时注册了钩子函数具体看packet_create函数的实现。static const struct net_proto_familypacket_family_ops = { .family= PF_PACKET, .create= packet_creat...
2018-05-08 20:10:41
2164
转载 Debugging Analysis of Kernel panics and Kernel oopses using System Map
内核问题定位
2017-09-25 11:21:13
925
原创 收包函数调用流程
linux 内核数据报文接收流程[70977.808241] [] ? tcp_ack+0xd8a/0x1390 [70977.887555] [] ? tcp_rcv_established+0x18a/0x6a0[70977.978619] [] ? tpacket_rcv+0x50/0x800[70978.044437] [] ? tcp_v4_do_rcv+0x1
2017-07-31 09:40:03
774
原创 centos 7 取消LOG输出限制
Add the following to /etc/rsyslog.conf after '$ModLoad imuxsock' and '$ModLoad imjournal':$IMUXSockRateLimitInterval 0$IMJournalRatelimitInterval 0Set the following in /etc/systemd/journald.co
2017-01-11 14:07:26
1411
转载 /proc/kallsyms
T The symbol is in the text(code) sectionD The symbol is in the initialized data sectionR The sysbol is in a read only data sectiont staticd staticR constr static const
2016-08-04 15:46:12
542
转载 Controlling which congestion control algorithm is used in Linux
set congestion control algorithm per-socket
2016-07-11 21:11:29
429
原创 判断一个整数是否是n^m次方类型数据,并比较乘法和除法性能差异
求取a = n^m #include #include #include int testnum(int num, int base){ if (num <= 0 || num < base || num % base != 0) return -1; if(num == base) return 1; num = num/base; return nu
2015-04-27 21:17:22
459
转载 Coping with the TCP TIME-WAIT state on busy Linux servers
Coping with the TCP TIME-WAITstate on busy Linux serversVincent BernatFebruary 24, 2014Also available in FrançaisFiled under NetworkTwitter Google+
2015-04-06 09:43:37
863
转载 linux kernel 2.6.35中RFS特性详解
本文链接地址: linux kernel 2.6.35中RFS特性详解前面我介绍过google对内核协议栈的patch,RPS,它主要是为了软中断的负载均衡,这次继续来介绍google 的对RPS的增强path RFS(receive flow steering),RPS是把软中断map到对应cpu,而这个时候还会有另外的性能影响,那就是如果应用程序所在的cpu和软中断处理的cpu不是
2015-03-31 15:20:52
654
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人