NetFilterHook: Displaly Interface Name

2019-08-06 07:52发布

How can filter and/or display the name of the interface the packet has arrived from in the Kernel space?

More specifcally I want the name of the interfacen e.g eth0, wlan1 etc to be printed out in the kernel.

Secondly how can I filter packets only from a specific interface e.g eth0 only?

1条回答
迷人小祖宗
2楼-- · 2019-08-06 08:12

In the hook function, there is parameters const struct net_device *in and const struct net_device *out. You can print it by:

printk(KERN_INFO "%s\n", out->name);

or:

printk(KERN_INFO "%s\n", in->name);

Note: You need to check if is null.

About the second question, you can use in the hook function in strcmp(in->name, "eth0"), and then decide drop or accept.

查看更多
登录 后发表回答