问题描述
我正在编写一个Linux内核模块,当链接上升/下降时需要通知它,现在我读到可以打开netlink socket
并收听RTMGRP_LINK
(网络接口创建/删除) /up/down事件)多播组,但这是从用户空间使用的...任何人都知道如何从内核空间捕获此中断?我正在使用内核2.6.35
I'm writing a linux kernel module that needs to be notified when a link goes up/down, now I've read that I can open a netlink socket
and listen to the RTMGRP_LINK
(network interface create/delete/up/down events) multicast groups, but this is used from user space... any one knows how to catch this interrupt from kernel space? I'm using kernel 2.6.35
推荐答案
查找<linux/netdevice.h>
,特别是有关netdev通知程序链的内容.您可以调用register_netdevice_notifier()
来注册一个回调(在许多其他事件类型中),该回调将接收NETDEV_UP
和NETDEV_DOWN
事件.
Look in <linux/netdevice.h>
, specifically the stuff about the netdev notifier chain. You can call register_netdevice_notifier()
to register a callback that (among many other event types) will receive NETDEV_UP
and NETDEV_DOWN
events.
这篇关于如何捕捉网卡中断(上/下)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!