我已经virtual network interface
将其收到的packet
转发到物理接口eth2
,目的是将其发送到需要的任何目的地。
虚拟接口的hard_start_xmit
功能接收数据包,更改源MAC and IP
,将处理设备设置为物理接口,并将数据包类型设置为PACKET_OUTGOING
static int forward_packet(struct sk_buff *skb, struct net_device *dev) {
char switched_device_name[] = "eth2";
struct net_device *switched_device = dev_get_by_name(switched_device_name);
int ifrx_output;
u32 switched_device_ip;
if (!switched_device) {
printk("Error: Couldn't get device %s for switching.\n", switched_device_name);
return -1;
}
skb->dev = switched_device;
skb->input_dev = switched_device;
skb->pkt_type = PACKET_OUTGOING;
switched_device_ip = get_interface_ip(switched_device);
change_source_mac_and_ip(skb, switched_device->dev_addr, switched_device_ip);
ifrx_output = netif_rx(skb);
printk("netif_rx returned %d.\n", ifrx_output);
return 0;
}
我测试了这段代码,虽然数据包确实出现在物理接口tcpdump
中,但目标计算机上没有它的踪迹。
我能想到这样的事情的唯一原因是因为物理接口将其视为传入数据包而无需传递它。但据我所知,只有skb->pkt_type
才能确定。
我可能缺少哪些其他数据包更改?