How do I set a network interface to promiscuous mode in a kernel module?
You can use the following function (which is in net / core / dev.c):
int dev_set_promiscuity(struct net_device *dev, int inc)
If you want to set the device in promiscuous mode, then it inc
should be 1. To disable the skipped mode, set inc
to -1. For the function to work, you need to block rtnl. To get it, you need to call the following functions before and after the call dev_set_promiscuity()
(functions found in net / core / rtnetlink.c):
void rtnl_lock(void);
void rtnl_unlock(void);
source to share
When I use dev_set_promiscuity (dev_eth0,1) it appears in the dmesg command:
[550.411935] RTNL: Assertion failed to net / core / dev.c (4059)
[550.411940] Pid: 5164, comm: insmod Tainted: P 2.6.35101
[550.411943] Call trace:
[550.411951] []? printk + 0x25 / 0x29
[550.411956] [] __dev_set_promiscuity + 0x37 / 0x127
[550.411960] [] dev_set_promiscuity + 0x18 / 0x37
[550.411965] []? hook_init + 0x0 / 0x88 [nethook]
[550.411969] [] hook_init + 0x3a / 0x88 [nethook]
[550.411973] [] do_one_initcall + 0x4f / 0x139
[550.411978] []? blocking_notifier_call_chain + 0x11 / 0x13
[550.411982] [] sys_init_module + 0x7f / 0x19b
[550.411986] [] sysenter_do_call + 0x12 / 0x28
[550.411989] device eth0 entered promiscuous mode
RTNL: Assertion failed in net / core / dev.c (4059), this happens and after a while error messages and kernel crashes appear.
Does anyone know how to solve this? Regards
source to share