免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 767 | 回复: 0
打印 上一主题 下一主题

[内核入门] 对原始skb进行了值得修改,但对check赋初值为0后运行校验和函数就死机.. [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2016-04-19 16:51 |只看该作者 |倒序浏览
拜托大家帮我看看....自己制作了一个synack包并发送出去,是直接对原来的skb进行了修改(因为重新构造的时候一直出错死机没找出原因所以直接修改的skb)
本来可以运行的但是我发现忘记把niph->check置0.所以求出来的校验和是错的,于是我就在前面加了一句置0...结果就一直死机没法再运行了

测试发现我的niph->check = 0,和 ip_fast_csum不能同时存在,,,一同时存在就死机,,不知道为什么
我用return一句句试发现运行到487行的时候死机的(代码如下), 没加check = 0时是可以正常运行的..求大家帮我看看哪里有错呀

445         struct sk_buff *nskb = NULL;
446         struct ethhdr *neth = NULL;
447         const struct iphdr *oiph = ip_hdr(oldskb);
448         struct iphdr *niph = NULL;
449         const struct tcphdr *oth = tcp_hdr(oldskb);
450         struct tcphdr *tcph = NULL;//_otcph
451         struct ethhdr *oeth = eth_hdr(oldskb);
452         int length = 0;
459         if (oth == NULL)
460            return;
461
462         nskb = oldskb;   //直接改的原来的skb
463         if(!nskb){
464         printk(KERN_EMERG "the nskb is null\n");
465         return;
466         }
467
468         niph = ip_hdr(nskb);
469         tcph = (struct tcphdr *)((void *)niph + (niph->ihl << 2));
470
471        //tcp头
472         tcph->source = 47138;
473         tcph->dest = 20500;
474         tcph->seq = htonl(isn);
475         tcph->ack_seq = htonl(isn);
476         tcph->ack = 1;
477
478         //ip头  我都是直接赋值的,赋的值是正确的
479
480         niph->saddr         = 16777226;
481         niph->daddr         = 33554442;
482         niph->check = 0;//加了这句之后就死机了ip checksum
483         niph->check = ip_fast_csum((unsigned char *)niph,niph->ihl);
485         neth = eth_hdr(nskb);
486         ether_addr_copy(neth->h_dest,oeth->h_source);
487         ether_addr_copy(neth->h_source,key->eth.dst); //这个key->eth.dst值是正确的, 运行到这就死机了
488
597         length = tcph->doff << 2;
604         tcph->check = ~tcp_v4_check(length,niph->saddr,niph->daddr,0);
605
606         nskb->ip_summed = CHECKSUM_PARTIAL;
607
608         nskb->csum_start = (unsigned char *)tcph - nskb->head;
609         nskb->csum_offset = offsetof(struct tcphdr,check);
610         nskb->pkt_type = PACKET_OTHERHOST;
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP