- 论坛徽章:
- 0
|
本帖最后由 lawrence2013 于 2013-06-04 15:21 编辑
大家好,我netfilter的local out hook钩到数据包,然后通过dev_queue_xmit发送出去。数据包能正常发送出去,而且对段也能正常收到,但目前的问题是机器频繁死机。如果我把函数dev_queue_xmit禁了,机器就比较稳定了。请你们帮我看下是不是的代码有什么问题?是不是可能在dev_queue_xmit有死锁了?谢谢!
static unsigned int modify(unsigned int hooknum, struct sk_buff * skb,
const struct net_device * in, const struct net_device * out,
int (*okfn)(struct sk_buff *))
{
struct sk_buff* nskb = NULL;
struct iphdr* nip_hdr = NULL;
struct ethhdr* neth_hdr = NULL;
struct icmphdr *icmph = NULL;
int tot_len;
int iph_len;
int iph_off;
int ret = 0;
nskb = skb;
nip_hdr = ip_hdr(nskb);
iph_len = ip_hdrlen(nskb);
iph_off = nip_hdr->ihl << 2;
tot_len = ntohs(nip_hdr->tot_len);
if((nip_hdr->protocol != IPPROTO_ICMP))
{
return NF_ACCEPT;
}
skb_pull(nskb, iph_len);
skb_reset_transport_header(nskb);
if(nip_hdr->protocol == IPPROTO_ICMP)
{
icmph = icmp_hdr(nskb);
icmph->checksum = 0;
nskb->csum = 0;
nskb->csum = csum_partial((unsigned char *)icmph, tot_len - iph_len, 0);
icmph->checksum = in_cksum((unsigned short *)icmph,
ntohs(nip_hdr->tot_len) - sizeof(struct iphdr));
}
nip_hdr->check = 0;
nip_hdr->check = ip_fast_csum((unsigned char *)nip_hdr, nip_hdr->ihl);
nskb->ip_summed = CHECKSUM_NONE;
nskb->pkt_type = PACKET_OUTGOING;
nskb->dev = dev_get_by_name(&init_net,ETH);
if(nskb->dev==NULL)
{
printk("%s\n", "dev_get_by_name return NULL");
//kfree_skb(nskb);
return NF_ACCEPT;
}
dev_put(nskb->dev);
skb_push(nskb, iph_len);
neth_hdr = (struct ethhdr *)skb_push(nskb, ETH_HLEN);
skb_reset_mac_header(nskb);
nskb->protocol = neth_hdr->h_proto = htons(ETH_P_IP);
memcpy(neth_hdr->h_source, nskb->dev->dev_addr, ETH_ALEN);
memcpy(neth_hdr->h_dest, DEST, ETH_ALEN);
ret = dev_queue_xmit(nskb);
if(ret != NET_XMIT_SUCCESS){
printk("ret:%d\n", ret);
}
return NF_STOLEN;
} |
|