Recent Posts
-
April 15, 2022
Golang程序随机出现cpu 100%的bug
https://github.com/golang/go/issues/51654 v1.16.7 ~ v1.18 都会出现这个bug。线上的机器遇到的好像就是这个问题,golang的应用一天中随机出现几次cpu 100%的问题,过几秒可能就恢复正常.看描述好像说是在不同的goroutine里面修改同一个Timer场景会导致这个问题。用perf采样,cpu利用率调用栈大概是这样的。 32.70% [.] runtime.stealWork 12.51% [...
-
April 15, 2022
Golang程序加载tls证书的代码
func loadTLSConfig(c *ServiceConfig) *tls.Config { cfg := &tls.Config{} if len(c.CertFile) > 0 && len(c.KeyFile) > 0 { cert, err := tls.LoadX509KeyPair(c.CertFile, c.KeyFile) // "example-cert.pem" "example-key.pem if err != nil...
-
March 29, 2022
Linux的lo网络设备loopback
dev.c 文件里面net_dev_init 函数会为每个net创建和初始化loopback_dev,在路由模块等地方会引用到这个loopback设备。 典型的比如local output的流量在 ip rule里面对应的iif就是 lo(loop back)设备。struct net { struct net_device *loopback_dev; /* The loopback */}/* Setup and register the loop...
-
March 24, 2022
Jsoniter里面解码某个json节点为特定struct
package mainimport ( jsoniter "github.com/json-iterator/go")type Info map[string]stringfunc main() { input := []byte(`{"type":"test","desc":"test","info":[{"a": "dd", "b":"ddd"}]}`) m := map[string]interface{}{} var info []GuestInfo var json = jso...
-
February 09, 2022
Netfilter自定义target和iptables的支持 以nflog为例
http://git.netfilter.org/iptables/tree/extensions/libipt_ULOG.chttps://elixir.bootlin.com/linux/latest/source/net/netfilter/nfnetlink_log.c https://elixir.bootlin.com/linux/latest/source/net/netfilter/nf_log_syslog.c https://elixir.bootlin.com/l...
-
January 08, 2022
Bpf和xdp代码的编译和加载和redhat的xdp Filter防火墙过滤
需要用clang把c语言写的代码编译成ebpf的object文件,然后用工具把object文件加载到内核。不过也有纯golang的库用于编译和调试ebpf的 https://github.com/cilium/ebpf也有很多辅助工具用于加载bpf代码,比如https://github.com/iovisor/bcc 用于调试分析系统,已经集成了很多脚本了吧,好像可以取代systemtap.BPF and XDP Reference Guide https://docs.cilium.i...
-
January 07, 2022
基于bpf技术的文件和进程安全监控项目falco
https://github.com/falcosecurity/falcohttps://falco.org/docs/可以根据配置的规则把文件变化、进程和socket事件通过grpc发送告警。What does Falco do?Falco uses system calls to secure and monitor a system, by:Parsing the Linux system calls from the kernel at runtimeAsserting the ...
-
December 18, 2021
Iptables Nft的rule规则匹配和执行情况的检查log和调试track
iptables提供了log和trace这2个target,nlog是写内核日志,trace是更详细的规则执行步骤和各个情况。log的使用的例子,打印dns包iptables -t mangle -i eth3 -I PREROUTING 1 -p udp -m udp --dport 53 -j LOG --log-prefix '==dns== 'iptables -t raw -A PREROUTING -p udp -m udp --dport 53 -j TRACExtable...
-
November 08, 2021
Linux的和bios的acpi兼容问题和acpi_osi启动参数可能影响reboot命令
之前有遇到,bios里面“操作系统类型”设置会影响linux的reboot命令,不设置为“linux”类型,linux的reboot命令不起作用。看网上很多帖子提到linux的重启问题和acpi_osi参数有关系,估计是bios的兼容问题吧。这篇官方解释比较详细: https://www.kernel.org/doc/html/latest/firmware-guide/acpi/osi.html完整的acpi参数参考, acpi_osi acpi_os_name这两个比较相关吧,可以参...
-
October 28, 2021
Linux的xdp里面也可以把网络包重定向到特定的cpu类似网卡rfs功能
Receive Side Scaling (RSS) with eBPF and CPUMAPhttps://developers.redhat.com/blog/2021/05/13/receive-side-scaling-rss-with-ebpf-and-cpumap#faster_software_receive_steering_with_xdphttps://github.com/torvalds/linux/blob/master/kernel/bpf/cpumap.c就是...