When developing virtual network device drivers for Linux, sometimes there is a need of redirecting packets between the real device and a virtual one. Fortunately, the Linux kernel (version 4.14 in our case) has the right tools to do so, without any extra headache. Let’s look at redirecting incoming packets from a real network device. To do so, you don’t even have to change the sources of a real network driver itself. All you need to do is just use the mechanism of rx_handlers. To add your own handler, you need to use the following API call from your virtual driver:
int netdev_rx_handler_register (
struct net_device * dev,
rx_handler_func_t * rx_handler,
void * rx_handler_data);