Linux内核Netconsole

1. netconsole

当量产或试产的机器已经出货,产品出现系统问题却不能像应用层可以获取日志进行分析,出现问题只能拆机监听uart串口,因此将内核调试信息传递到网络并且查看成为一个产品所支持的必要手段。netconsole就是把内核调试信息通过网络传递到本地输出,完美解决痛点。

2. netconsole编译

netconsole默认是编译进内核,并且是可选编译的。以下以hi3516ev300sdk举例:osdrv\opensource\kernel\linux-4.9.y\drivers\net\Makefile

#
# Networking Core Drivers
#
obj-$(CONFIG_BONDING) += bonding/
obj-$(CONFIG_IPVLAN) += ipvlan/
obj-$(CONFIG_DUMMY) += dummy.o
obj-$(CONFIG_EQUALIZER) += eql.o
obj-$(CONFIG_IFB) += ifb.o
obj-$(CONFIG_MACSEC) += macsec.o
obj-$(CONFIG_MACVLAN) += macvlan.o
obj-$(CONFIG_MACVTAP) += macvtap.o
obj-$(CONFIG_MII) += mii.o
obj-$(CONFIG_MDIO) += mdio.o
obj-$(CONFIG_NET) += Space.o loopback.o
obj-$(CONFIG_NETCONSOLE) += netconsole.o
...

2.1 编译条件

build-in-kernel

开启编译选项如下:

make ARCH=arm CROSS_COMPILE=arm-himix100-linux- menuconfig

Device Drivers > Network device support>Network console logging support

build-in-modules

make ARCH=arm CROSS_COMPILE=arm-himix100-linux- CONFIG_NETCONSOLE=m drivers/net/

实际上可以在编译menuconfig选择M编译成模块

make ARCH=arm CROSS_COMPILE=arm-himix100-linux- modules

2.2 ko使用

报错解决一

insmod: can't insert 'netconsole.ko': unknown symbol in module, or unknown parameter

编译后需要重新烧录新的内核

报错解决二

netpoll: netconsole: local port 6665
netpoll: netconsole: local IPv4 address 192.168.0.240
netpoll: netconsole: interface 'eth0'
netpoll: netconsole: remote port 6666
netpoll: netconsole: remote IPv4 address 192.168.0.130
netpoll: netconsole: remote ethernet address 00:0c:29:9f:c6:6d
netpoll: netconsole: eth0 doesn't support polling, aborting
netconsole: cleaning up
insmod: can't insert 'netconsole.ko': Unknown error 524

验证功能用的是hi3516ev300sdk,以下内容仅作为参考不做实际应用(参考):
\linux-4.9.y\drivers\net\ethernet\hisilicon\hisi-femac\hisi_femac.c

#ifdef CONFIG_NET_POLL_CONTROLLER
static void hisi_femac_set_poll_controller(struct net_device *dev)
{
	struct hisi_femac_priv *priv = netdev_priv(dev);
    hisi_femac_irq_disable(priv, dev->irq);
	hisi_femac_irq_enable(priv, dev->irq);
}
#endif


static const struct ethtool_ops hisi_femac_ethtools_ops = {
    .get_link = ethtool_op_get_link,
    .get_link_ksettings = phy_ethtool_get_link_ksettings,
    .set_link_ksettings = phy_ethtool_set_link_ksettings,
    .get_pauseparam = hisi_femac_get_pauseparam,
    .set_pauseparam = hisi_femac_set_pauseparam,
};

static const struct net_device_ops hisi_femac_netdev_ops = {
    .ndo_open = hisi_femac_net_open,
    .ndo_stop = hisi_femac_net_close,
    .ndo_start_xmit = hisi_femac_net_xmit,
    .ndo_do_ioctl = hisi_femac_net_ioctl,
    .ndo_set_mac_address = hisi_femac_set_mac_address,
    .ndo_set_rx_mode = hisi_femac_net_set_rx_mode,
    .ndo_change_mtu = eth_change_mtu,
    .ndo_set_features = hisi_femac_set_features,
	.ndo_poll_controller = hisi_femac_set_poll_controller
};

实际操作(ubuntu监听hi3516ev300)

  • 目标机器获取监测主机MAC地址(处于同一局域网)

    ping -c 1 192.168.0.130 > /dev/null
    arp -n 192.168.0.130
    ? (192.168.0.130) at 00:0c:29:9f:c6:6d [ether]  on eth0
    
  • 目标机器获取监测主机MAC地址(处于不同局域网)

    $ netstat -rn | grep ^0.0.0.0
     0.0.0.0         192.168.1.1     0.0.0.0         UG        0 0          0 eth0
    $ ping -c 1 192.168.0.1 > /dev/null
    $ arp -n 192.168.0.1
     Address                  HWtype  HWaddress           Flags Mask            Iface
     192.168.0.1              ether   00:0f:66:5b:2a:3c   C                     eth0
    
  • 启动netconsole

    insmod netconsole.ko netconsole=6665@192.168.0.240/eth0,6666@192.168.0.130/00:0c:29:9f:c6:6d
    
    ubuntu@ubuntu:~/share/project/netconsole$ netcat -l -p 6666 -u
    netlink: loading out-of-tree module taints kernel.
    netlink_broadcast failed?! (-3)
    sample init success.
    random: crng init done
    sample exit success.
    

3. 总结

netconsole是调试的一个手段,本次只是利用hi3516ev300进行一次验证,却刚好排查内核驱动不支持polling。

4. 参考资料

netconsole
内核崩溃排查工具
netconsole重定向kernel日志到远程服务器
Linux配置Netconsole远程打印日志信息
windows获取netconsole工具

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值