问题
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