NetFilterHook: Displaly Interface Name

安稳与你 提交于 2019-12-11 12:03:29

问题


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:


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.



来源:https://stackoverflow.com/questions/34480548/netfilterhook-displaly-interface-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!