我正在为e1000卡写一个网络驱动程序。在执行接收部分时,我看到内核在到达netif_rx(skb)调用时冻结。当我使用裸机驱动程序时,我能够重现相同的错误,我很难编写skb数据。
请参阅下面的测试功能代码。数据是TCP数据包(带有IP和以太网报头)的数据。当我将驱动程序加载到虚拟机时,我看到VM进程在主机中占用了100%以上的CPU。此后操作系统不响应输入。如果我注释掉netif_rx行,它似乎工作正常。
static void test_skb(void){
unsigned char t[] = {0x52,0x54,0x00,0x12,0x34,0x56,0x52,0x55,0x0a,0x00,0x02,0x02,0x08,0x00,0x45,0x00,0x00,0x2c,0x00,0x1c,0x00,0x00,0x40,0x06,0x62,0xa0,0x0a,0x00,0x02,0x02,0x0a,0x00,0x02,0x0f,0xc6,0x1a,0x1e,0xdb,0x4c,0x81,0x18,0x01,0x00,0x00,0x00,0x00,0x60,0x02,0x22,0x38,0x14,0x66,0x00,0x00,0x02,0x04,0x05,0xb4};
int len = 58;
struct sk_buff *skb;
skb = dev_alloc_skb (len + 2);
if (skb) {
printk("Allocated skb buffer\n");
memcpy(skb_put(skb, len), t, len);
printk("step1\n");
//skb_put(skb, len);
//skb->dev = dev;
printk("step2\n");
//skb->protocol = eth_type_trans(skb, dev);
skb->protocol = ETH_P_IP;
printk("step3\n");
skb->ip_summed = CHECKSUM_UNNECESSARY;
printk("step4\n");
//netif_rx (skb);
printk("step5\n");
}
printk(KERN_INFO"All Done");
if(skb){
dev_kfree_skb(skb);
}
}