*** interceptor.bak Thu Dec 17 12:13:32 2009 --- interceptor.c Thu Dec 17 12:18:43 2009 *************** *** 134,139 **** --- 134,148 ---- .notifier_call = handle_netdev_event, }; + #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,31) + static const struct net_device_ops vnet_netdev_ops = { + .ndo_start_xmit = interceptor_tx, + .ndo_get_stats = interceptor_stats, + .ndo_do_ioctl = interceptor_ioctl, + }; + #endif + + #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22) static #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24) *************** *** 146,156 **** --- 155,180 ---- #endif interceptor_init(struct net_device *dev) { + #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,31) + struct net_device_ops *ops_tmp; + #endif ether_setup(dev); + #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,31) + if (dev->netdev_ops) { + ops_tmp = (struct net_device_ops *) dev->netdev_ops; + ops_tmp->ndo_start_xmit = interceptor_tx; + ops_tmp->ndo_get_stats = interceptor_stats; + ops_tmp->ndo_do_ioctl = interceptor_ioctl; + dev->netdev_ops = ops_tmp; + } + else + { dev->netdev_ops = &vnet_netdev_ops; } + #else dev->hard_start_xmit = interceptor_tx; dev->get_stats = interceptor_stats; dev->do_ioctl = interceptor_ioctl; + #endif dev->mtu = ETH_DATA_LEN-MTU_REDUCTION; kernel_memcpy(dev->dev_addr, interceptor_eth_addr,ETH_ALEN); *************** *** 260,265 **** --- 284,292 ---- static int add_netdev(struct net_device *dev) { + #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,31) + struct net_device_ops *ops_tmp; + #endif int rc = -1; int i = 0; *************** *** 288,295 **** --- 315,329 ---- Bindings[i].original_mtu = dev->mtu; /*replace the original send function with our send function */ + #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,31) + Bindings[i].InjectSend = dev->netdev_ops->ndo_start_xmit; + ops_tmp = (struct net_device_ops*)dev->netdev_ops; + ops_tmp->ndo_start_xmit = replacement_dev_xmit; + dev->netdev_ops = ops_tmp; + #else Bindings[i].InjectSend = dev->hard_start_xmit; dev->hard_start_xmit = replacement_dev_xmit; + #endif /*copy in the ip packet handler function and packet type struct */ Bindings[i].InjectReceive = original_ip_handler.orig_handler_func; *************** *** 303,308 **** --- 337,345 ---- static int remove_netdev(struct net_device *dev) { + #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,31) + struct net_device_ops *ops_tmp; + #endif int rc = -1; BINDING *b; *************** *** 311,317 **** --- 348,360 ---- if (b) { rc = 0; + #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,31) + ops_tmp = (struct net_device_ops*)dev->netdev_ops; + ops_tmp->ndo_start_xmit = b->InjectSend; + dev->netdev_ops = ops_tmp; + #else dev->hard_start_xmit = b->InjectSend; + #endif kernel_memset(b, 0, sizeof(BINDING)); } else